Bug #66330 [Opn->Nab]: array_unique() sort problems

From: Date: Fri, 20 Dec 2013 17:36:26 +0000
Subject: Bug #66330 [Opn->Nab]: array_unique() sort problems
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183422@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66330&edit=1 ID: 66330 Updated by: bwoebi@php.net Reported by: nomail at nomail dot de Summary: array_unique() sort problems -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: Windows PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php SORT_NUMERIC actually casts to integer and then compares; strings without numbers in it just are casted to 0 during an int cast. If you cast the array, it results in array(0, 0, 0, 0, 234, 0, 0); And when you apply array_unique to that array, you notice that that's correct behaviour. Previous Comments: ------------------------------------------------------------------------ [2013-12-20 14:05:01] nomail at nomail dot de Description: ------------ The Sort_Flags are not realy working. Only SORT_NUMERIC and this on a unexpected way, it loose some values. Your menu to select my phpversion has not my Version includet, so my Version is: 5.4.7 Test script: --------------- $ar = array('rot','gelb','grün','rot','234fw343','blau','gold'); $ar1 = array_unique($ar); $ar2 = array_unique($ar,SORT_REGULAR); $ar3 = array_unique($ar,SORT_NUMERIC); $ar4 = array_unique($ar,SORT_STRING); $ar5 = array_unique($ar,SORT_LOCALE_STRING); print_r($ar1); print_r($ar2); print_r($ar3); print_r($ar4); print_r($ar5); Expected result: ---------------- ### Output #### ##### NOT EXPECTED, this is the unexpected Output ##### Array ( [0] => rot [1] => gelb [2] => grün [4] => 234fw343 [5] => blau [6] => gold ) Array ( [0] => rot [1] => gelb [2] => grün [4] => 234fw343 [5] => blau [6] => gold ) Array ( [0] => rot [4] => 234fw343 ) Array ( [0] => rot [1] => gelb [2] => grün [4] => 234fw343 [5] => blau [6] => gold ) Array ( [0] => rot [1] => gelb [2] => grün [4] => 234fw343 [5] => blau [6] => gold ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66330&edit=1

« previous php.bugs (#183422) next »