note 50651 added to function.array-flip
| From: | benles at bldigital dot com | Date: | Sun, 06 Mar 2005 01:52:03 +0000 |
| Subject: | note 50651 added to function.array-flip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85982@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/function.array-flip.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50651
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50651&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50651&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50651&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50651&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50651&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50651&report=yes
Search -- http://master.php.net/manage/user-notes.php