note 43099 deleted from function.http-build-query by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 09 Jun 2004 18:57:08 +0000 |
| Subject: | note 43099 deleted from function.http-build-query by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70517@lists.php.net to get a copy of this message | ||
Note Submitter: brainstar@gmail.com
----
You can also use this "userland" function to do the same thing.
<?
//http_build_query it is not supported until PHP 5
function my_http_build_query ($getarray) {
if (!is_array($getarray))
return "";
//go throuh each of the base params
$getquery = "";
foreach ($getarray as $name => $value) {
//call the recurse to go through each array within array...etc
my_http_build_query_recurse($getquery, $name, $value);
}
return $getquery;
}
function my_http_build_query_recurse (&$getquery, $nameprefix, $input) {
//check if this input is an array
if (is_array($input)) {
//then we need to interate it
//and add values for each of its elements
//build on the nameprefix so we can do any level of nested arrays
foreach ($input as $index => $value) {
my_http_build_query_recurse($getquery, $nameprefix . "[" . $index . "]",
$value);
}
} else {
//otherwise just output this param
if (isset($input)) {
if ($getquery != "")
$getquery .= "&";
$getquery .= $nameprefix . "=" . $input;
}
}
}
?>