note 55994 deleted from function.implode by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 13:16:49 +0000 |
| Subject: | note 55994 deleted from function.implode by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189726@lists.php.net to get a copy of this message | ||
Note Submitter: info at urbits dot com
----
I liked memandeemail's (27-Apr-2005) neat code for imploding an associative array. I have done
a mod so that, by default, it returns a url query string.
<?php
function implode_with_key($assoc, $inglue = '=', $outglue = '&')
{
$return = null;
foreach ($assoc as $tk => $tv) $return .= $outglue.$tk.$inglue.$tv;
return substr($return,1);
}
?>
Example:
<?php
$assoc_array = array("a" => "foo", "b" => "bar",
"c" => "foobar");
echo (implode_with_key($assoc_array);
?>
ouput: a=foo&b=bar&c=foobar
usage: After altering the $HTTP_GET_VARS values, I pass $HTTP_GET_VARS to the function to easily
build variation urls for links and header redirects.
note: This function doesn't encode the url string or check for empty variables.