note 81484 added to function.array-flip
| From: | Anonymous at osu1 dot php dot net | Date: | Fri, 29 Feb 2008 19:45:05 +0000 |
| Subject: | note 81484 added to function.array-flip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136614@lists.php.net to get a copy of this message | ||
True, array_unique does preserve keys, but if you are incrementing in a loop, then it will stop once
the key values break numerical order. If you don't care about preserving keys, a life-saver
(originally a headache) for me was...
<?php
$new_array = array_keys(array_flip($old_array));
?>
i used this little snip-it after results from preg_match_all() as a way to remove duplicates from an
array and then re-organize the numerical keys ;)
*Only works on arrays with numerical keys.
----
Server IP: 209.41.74.194
Probable Submitter: 192.251.134.5
----
Manual Page -- http://www.php.net/manual/en/function.array-flip.php
Edit -- https://master.php.net/note/edit/81484
Del: integrated -- https://master.php.net/note/delete/81484/integrated
Del: useless -- https://master.php.net/note/delete/81484/useless
Del: bad code -- https://master.php.net/note/delete/81484/bad+code
Del: spam -- https://master.php.net/note/delete/81484/spam
Del: non-english -- https://master.php.net/note/delete/81484/non-english
Del: in docs -- https://master.php.net/note/delete/81484/in+docs
Del: other reasons-- https://master.php.net/note/delete/81484
Reject -- https://master.php.net/note/reject/81484
Search -- https://master.php.net/manage/user-notes.php