note 66470 deleted from function.implode by hholzgra

From: Date: Thu, 02 Aug 2012 13:17:17 +0000
Subject: note 66470 deleted from function.implode by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189732@lists.php.net to get a copy of this message
Note Submitter: adnan at barakatdesigns dot net ---- 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', '&amp;'), 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&amp;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' */ ?>

« previous php.notes (#189732) next »