Converting Arrays to Query Strings in PHP


Use http_build_query() to create a URL-encoded query string from an associative array.

Source Code

$data = ['name' => 'John Doe', 'age' => 22, 'city' => 'New York'];
$queryString = http_build_query($data);
echo $queryString; // Outputs: name=John+Doe&age=22&city=New+York
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments