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