note 55994 added to function.implode
| From: | info at urbits dot com | Date: | Sat, 20 Aug 2005 01:06:40 +0000 |
| Subject: | note 55994 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93932@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.implode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55994
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55994&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55994&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55994&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55994&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55994&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55994&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55994&report=yes
Search -- http://master.php.net/manage/user-notes.php