note 50651 deleted from function.array-flip by danbrown
| From: | danbrown@php.net | Date: | Fri, 14 May 2010 15:04:10 +0000 |
| Subject: | note 50651 deleted from function.array-flip by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169252@lists.php.net to get a copy of this message | ||
Note Submitter: benles at bldigital dot com
----
In case anyone wants a function that doesn't lose duplicates:
function array_invert($arr)
{
$res = Array();
foreach(array_keys($arr) as $key)
{
if (!array_key_exists($arr[$key], $res)) $res[$arr[$key]] = Array();
array_push($res[$arr[$key]], $key);
}
return $res;
}