note 43095 deleted from function.http-build-query by vincent

From: Date: Wed, 09 Jun 2004 18:29:35 +0000
Subject: note 43095 deleted from function.http-build-query by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-70439@lists.php.net to get a copy of this message
Note Submitter: brainstar@gmail.com ---- Since this is not available until PHP 5 I wrote a "userland" function to perform much the same task in earlier versions of PHP. <? //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; } } } ?>

« previous php.notes (#70439) next »