PHP function to build query string from array

后端 未结 5 483
暖寄归人
暖寄归人 2020-11-28 20:55

I\'m looking for the name of the PHP function to build a query string from an array of key value pairs. Please note, I am looking for the built in PHP function to d

5条回答
  •  攒了一身酷
    2020-11-28 21:02

    As this question is quite old and for PHP, here is a way to do it in the (currently) very popular PHP framework Laravel.

    To encode the query string for a path in your application, give your routes names and then use the route() helper function like so:

    route('documents.list.', ['foo' => 'bar']);
    

    The result will look something like:

    http://localhost/documents/list?foo=bar
    

    Also be aware that if your route has any path segment parameters e.g. /documents/{id}, then make sure you pass an id argument to the route() parameters too, otherwise it will default to using the value of the first parameter.

提交回复
热议问题