note 7791 added to array_unique

From: Date: Tue, 15 Aug 2000 18:08:42 +0000
Subject: note 7791 added to array_unique
Groups: php.notes 
Request: Send a blank email to php-notes+get-1909@lists.php.net to get a copy of this message
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: 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; } http://www.php.net/manual/function.array-unique.php

« previous php.notes (#1909) next »