Bug #17750 Updated: array_unique is not returning array[0] when all values are equal
| From: | venaas@php.net | Date: | Wed, 19 Jun 2002 07:00:45 +0000 |
| Subject: | Bug #17750 Updated: array_unique is not returning array[0] when all values are equal | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-11345@lists.php.net to get a copy of this message | ||
ID: 17750
Updated by: venaas@php.net
Reported By: thiago@softexpert.com
-Status: Open
+Status: Closed
Bug Type: Arrays related
Operating System: Windows 2000
PHP Version: 4.2.1
New Comment:
I've now made it always keep the first (independent of
sorting algorithm used). In your example the result
should now be array(0 => 8). So far this is only in CVS
and latest snapshots.
Previous Comments:
------------------------------------------------------------------------
[2002-06-13 13:35:38] thiago@softexpert.com
<?php
$array = array(0 => 8, 1 => "8", 2 => "8");
$array = array_unique($array);
print_r($array);
?>
The manual says:
=== MANUAL BEGIN ===
array_unique() takes input array and returns a new array without
duplicate values.
Note that keys are preserved. array_unique() sorts the values treated
as string at first, then will keep the first key encountered for every
value, and ignore all following keys. It does not mean that the key of
the first related value from the unsorted array will be kept.
Note: Two elements are considered equal if and only if (string) $elem1
=== (string) $elem2. In words: when the string representation is the
same.
The first element will be used.
==== MANUAL END ====
So, it should return $array[1], right ?
Its always returning the last value.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17750&edit=1