note 16666 added to function.array-unique

From: Date: Thu, 08 Nov 2001 11:57:40 +0000
Subject: note 16666 added to function.array-unique
Groups: php.notes 
Request: Send a blank email to php-notes+get-20601@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. -- http://www.php.net/manual/en/function.array-unique.php http://master.php.net/manage/user-notes.php?action=edit+16666 http://master.php.net/manage/user-notes.php?action=delete+16666 http://master.php.net/manage/user-notes.php?action=reject+16666

« previous php.notes (#20601) next »