note 58237 added to function.array-unique
| From: | webcreator at centrum dot cz | Date: | Fri, 28 Oct 2005 11:25:27 +0000 |
| Subject: | note 58237 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97737@lists.php.net to get a copy of this message | ||
array_unique function starts its comparation from beginning and pop the key off if there is more
values inside array. The last one remains. But i needed to hold priority of the order of values and
let the first one in.
Here is my easy solution:
##---
function my_array_unique($from)
{
for ($i=count($from);$i>1;$i--)
{
$last = $from[$i];
$from[$i] = "";
if (!in_array($last,$from))
$from[$i]=$last;
}
return array_unique($from);
}
# One empty value remains in array.
# But its very easy to separate it while using output array.
----
Manual Page -- http://www.php.net/manual/en/function.array-unique.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58237
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58237&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58237&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58237&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58237&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58237&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58237&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58237&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58237&report=yes
Search -- http://master.php.net/manage/user-notes.php