note 66470 added to function.implode
| From: | adnan at barakatdesigns dot net | Date: | Tue, 23 May 2006 16:17:16 +0000 |
| Subject: | note 66470 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111890@lists.php.net to get a copy of this message | ||
An easier way of achieving the same result as implode_with_keys() - and quicker execution time:
<?
/* NOTE: $glue is not used if $is_query is true */
function implode_with_keys($array, $glue, $is_query = false) {
if($is_query == true) {
return str_replace(array('[', ']', '&'), array('%5B',
'%5D', '&'), http_build_query($array));
} else {
return urldecode(str_replace("&", $glue, http_build_query($array)));
}
}
echo implode_with_keys(array('a[1]' => 'some text', 'a[2]' =>
'even more text'), false, true);
/* Will output 'a%5B1%5D=some+text&a%5B2%5D=even+more+text' */
/* This won't break html validation */
echo implode_with_keys(array('a[1]' => 'foo bar', 'b' =>
'more text'), '|');
/* Will output 'a[1]=foo bar|b=more text' */
?>
----
Server IP: 84.18.202.180
Probable Submitter: 84.68.193.176
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.implode.php
Edit -- http://master.php.net/note/edit/66470
Del: integrated -- http://master.php.net/note/delete/66470/integrated
Del: useless -- http://master.php.net/note/delete/66470/useless
Del: bad code -- http://master.php.net/note/delete/66470/bad+code
Del: spam -- http://master.php.net/note/delete/66470/spam
Del: non-english -- http://master.php.net/note/delete/66470/non-english
Del: in docs -- http://master.php.net/note/delete/66470/in+docs
Del: other reasons-- http://master.php.net/note/delete/66470
Reject -- http://master.php.net/note/reject/66470
Search -- http://master.php.net/manage/user-notes.php