From f73e436d2b40de255f6091e1466c69b51abe65ce Mon Sep 17 00:00:00 2001 From: Damien Seguy Date: Thu, 12 Jul 2001 12:49:04 +0000 Subject: [PATCH] Added note about array_unique making case of value's types. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@51324 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/array.xml | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/functions/array.xml b/functions/array.xml index 996848db5b..992a3b5c8b 100644 --- a/functions/array.xml +++ b/functions/array.xml @@ -1378,7 +1378,11 @@ echo "sum(b) = ".array_sum($b)."\n"; array_unique takes input array and returns a new array without duplicate values. - Note that keys are preserved. + + + Note that keys are preserved. array_unique will + keep the first key encountered for every value, and ignore all + following keys. @@ -1386,12 +1390,40 @@ echo "sum(b) = ".array_sum($b)."\n"; $input = array ("a" => "green", "red", "b" => "green", "blue", "red"); $result = array_unique ($input); +print_r($result); +// this will output : +//Array +//( +// [a] => green +// [0] => red +// [1] => blue +//) - This makes $result have array ("a" => - "green", "red", "blue");. + Note that array_unique take into account + value's type. This is usually of no matter, except when it + comes to compare numbers, which can be of several types. + This may lead to confusing results. + + + + <function>array_unique</function> and types + +$input = array (4,"3",3,"4",4,4); +$result = array_unique ($input); +print_r($result); +// this will output : +//Array +//( +// [0] => 3 +// [1] => 3 +// [2] => 4 +// [3] => 4 +//) + +