note 69422 deleted from function.implode by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 13:17:27 +0000 |
| Subject: | note 69422 deleted from function.implode by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189734@lists.php.net to get a copy of this message | ||
Note Submitter: triptripon at gmail dot com
----
Here's my 2 matching (implode|explode)_with_key functions.
Notice, the inglue, outglue cannot appear within the keys\values.
function implode_with_key($assoc, $inglue = '>', $outglue = ',')
{
$return = '';
foreach ($assoc as $tk => $tv)
{
$return .= $outglue . $tk . $inglue . $tv;
}
return substr($return,strlen($outglue));
}
function explode_with_key($str, $inglue = ">", $outglue = ',')
{
$hash = array();
foreach (explode($outglue, $str) as $pair)
{
$k2v = explode($inglue, $pair);
$hash[$k2v[0]] = $k2v[1];
}
return $hash;
}
-- Tomer Levinboim