Function to build a query string
This is probably the most simple case of using http_build_query to build a query string. I'd say this is the best way to build a query string because you don't have to worry about whether or not you put an ampersand before appending a new variable and other cases like that. All you have to do is ensure your array is correct.
<?php
$data = array('foo'=>'bar',
'baz'=>'boom',
'cow'=>'milk',
'php'=>'hypertext processor');
echo http_build_query($data); // foo=bar&baz=boom&cow=milk&php=hypertext+processor
echo http_build_query($data, '', '& amp;'); // foo=bar&baz=boom&cow=milk&php=hypertext+processor
?>
$data = array('foo'=>'bar',
'baz'=>'boom',
'cow'=>'milk',
'php'=>'hypertext processor');
echo http_build_query($data); // foo=bar&baz=boom&cow=milk&php=hypertext+processor
echo http_build_query($data, '', '& amp;'); // foo=bar&baz=boom&cow=milk&php=hypertext+processor
?>
http://www.php.net/http_build_query »
[Click to add or edit comments])
Please prepend comments below including a date