note 61558 added to function.array-flip
| From: | mikeb at tracersinfo dot com | Date: | Mon, 06 Feb 2006 22:42:15 +0000 |
| Subject: | note 61558 added to function.array-flip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103142@lists.php.net to get a copy of this message | ||
Further deriving on benles -> crescentfreshpot, I think the following restatement of
array_invert() reads much easier and probably runs faster, too. It does yield the same results:
function array_invert($arr) {
$flipped = array();
foreach ( $arr as $k => $a ) {
# put the value in the key, with a throw-away value. dups are inherently avoided,
# though overwritten. not sure if prefixing with if ( !isset($flipped[$a][$k]) )
# would speed this up or slow it down. probably depends on quantity of dups.
$flipped[$a][$k] = NULL;
}
foreach ( $flipped as $k => $fl ) {
# now make the keys the values.
$flipped[$k] = array_keys($fl);
}
return $flipped;
}
----
Server IP: 64.71.164.2
Probable Submitter: 24.129.132.130
----
Manual Page -- http://www.php.net/manual/en/function.array-flip.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61558
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61558&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61558&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61558&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61558&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61558&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61558&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61558&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61558&report=yes
Search -- http://master.php.net/manage/user-notes.php