http_build_query with same name parameters

前端 未结 2 1315
南旧
南旧 2020-11-29 05:55

Is there a way to build a query automatically with http_build_query using parameters with the same name?

If I do something like

array(\'         


        
2条回答
  •  难免孤独
    2020-11-29 06:40

    This should do what you want, I had an api that required the same thing.

    $vars = array('foo' => array('x','y'));
    $query = http_build_query($vars, null, '&');
    $string = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $query); //foo=x&foo=y
    

提交回复
热议问题