Use http_build_query to generate query string

When adding query data to my http requests, I used to url-encode all the parameters and combine them together as a single url-encoded string manually. Today I found a PHP function that just does the job perfectly.


<?php
$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data) . "\n";
//This will output: foo=bar&baz=boom&cow=milk&php=hypertext+processor
echo http_build_query($data, '', '&amp;');
//This will output: foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor

?>

More details can be found here