Bug #14805 Updated: array_unique works opposed to the manual

From: Date: Wed, 02 Jan 2002 18:20:31 +0000
Subject: Bug #14805 Updated: array_unique works opposed to the manual
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-75622@lists.php.net to get a copy of this message
ID: 14805 User updated by: pgerzson@freestart.hu Reported By: pgerzson@freestart.hu Status: Open Bug Type: Arrays related Operating System: MS Windows 98 PHP Version: 4.0.6 New Comment: I forgot to mention that there may be something wrong with array_unique itself. There are three values of 3 considered equal in the example above: 2 => "3"(string), 4 => 3(int), 5 => "3" (string) [manual] " Two elements are considered equal if and only if (string) " $elem1 === (string) $elem2. In words: when the string " representation is the same." Why does array_unique use the index 4 in this case? (It's neither the first nor the latest key of value 3) Previous Comments: ------------------------------------------------------------------------ [2002-01-02 12:48:29] pgerzson@freestart.hu The manual (recent version from cvs) states that : " array_unique() will keep the first key encountered for every value, and ignore all following keys. " I've tested the two examples in this page and I've found this statement is not true. <?php $input = array (4,"4","3",4,3,"3"); $result = array_unique ($input); var_dump($result); ?> output: /* PHP 4.0.6 Win'98 PWS */ array(2) { [3]=> int(4) [4]=> int(3) } but the manual says it should print: array(2) { [0]=> int(4) [1]=> string(1) "3" } As you can recognize the latest keys are preserved for both value 4 and 3. ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=14805&edit=1

« previous php.dev (#75622) next »