note 71718 added to function.array-unique

From: Date: Wed, 13 Dec 2006 10:26:12 +0000
Subject: note 71718 added to function.array-unique
Groups: php.notes 
Request: Send a blank email to php-notes+get-120568@lists.php.net to get a copy of this message
Note that array_unique preserves the keys, even if the array is not associative: $values = Array("john@hotmail.com", "peter@hotmail.com", "will@hotmail.com", "john@hotmail.com", "laura@hotmail.com", "mariah@hotmail.com"); echo "<br>".count($values)." values.<br>"; var_dump($values); $unique_values = array_unique($values); echo "<br>".count($unique_values)." unique values.<br>"; var_dump($unique_values); RESULT: 6 values. array(6) { [0]=> string(16) "john@hotmail.com" [1]=> string(17) "peter@hotmail.com" [2]=> string(16) "will@hotmail.com" [3]=> string(16) "john@hotmail.com" [4]=> string(17) "laura@hotmail.com" [5]=> string(18) "mariah@hotmail.com" } 5 unique values. array(5) { [0]=> string(16) "john@hotmail.com" [1]=> string(17) "peter@hotmail.com" [2]=> string(16) "will@hotmail.com" [4]=> string(17) "laura@hotmail.com" [5]=> string(18) "mariah@hotmail.com" } $unique_values[3] is missing. Use array_merge or array_values if you need the index to be linear. ---- Server IP: 64.71.164.2 Probable Submitter: 62.15.153.234 ---- Manual Page -- http://www.php.net/manual/en/function.array-unique.php Edit -- https://master.php.net/note/edit/71718 Del: integrated -- https://master.php.net/note/delete/71718/integrated Del: useless -- https://master.php.net/note/delete/71718/useless Del: bad code -- https://master.php.net/note/delete/71718/bad+code Del: spam -- https://master.php.net/note/delete/71718/spam Del: non-english -- https://master.php.net/note/delete/71718/non-english Del: in docs -- https://master.php.net/note/delete/71718/in+docs Del: other reasons-- https://master.php.net/note/delete/71718 Reject -- https://master.php.net/note/reject/71718 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120568) next »