note 7791 modified in function.array-unique by vrana

From: Date: Tue, 17 Aug 2004 14:51:36 +0000
Subject: note 7791 modified in function.array-unique by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79872@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: <?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; } ?> --was-- 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://php.net/manual/en/function.array-unique.php

« previous php.notes (#79872) next »