note 7791 deleted from function.array-unique by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 17:26:49 +0000 |
| Subject: | note 7791 deleted from function.array-unique by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176205@lists.php.net to get a copy of this message | ||
Note Submitter: moose at ucdavis dot edu
----
Here's a little function I wrote that's similar to array_unique, for PHP3 users. It
actually removes duplicated elements, but only works for 1 dimensional arrays. It also doesn't
return a value, it changes the input array:
<?php
function array_unique(&$thearray)
{sort($thearray);
reset($thearray);
$newarray = array();
$i = 0;
$element = current($thearray);
for ($n=0;$n<sizeof($thearray);$n++)
{if (next($thearray) != $element)
{$newarray[$i] = $element;
$element = current($thearray);
$i++;
}
}
$thearray = $newarray;
}
?>