note 16666 deleted from function.array-unique by jimw

From: Date: Sat, 10 Nov 2001 23:28:32 +0000
Subject: note 16666 deleted from function.array-unique by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20689@lists.php.net to get a copy of this message
For PHP3 users or replaced boggus functions users: function My_in_array($needle,$haystack) {  for($i=0;$i<count($haystack) && $haystack[$i]!=$needle;$i++);  return ($i!=count($haystack)); } function My_array_unique(&$array) {  reset($array);  $newarray = array();  $element = current($array);  $key = key($array);  for ($n=0;$n<sizeof($array);$n++)  {   if (!My_in_array(next($array),$newarray))   {    $newarray[$key] = $element;    $element = current($array);    $key = key($array);   }  }  $array = $newarray; } Pro: Keep the key with value. Return exactly array_unique() expected result.

« previous php.notes (#20689) next »