Bug #65090 [Opn->Nab]: array_multisort() with SORT_NATURAL | SORT_FLAG_CASE results in incorrect order
| From: | ab@php.net | Date: | Sat, 22 Jun 2013 09:53:59 +0000 |
| Subject: | Bug #65090 [Opn->Nab]: array_multisort() with SORT_NATURAL | SORT_FLAG_CASE results in incorrect order | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-179692@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65090&edit=1
ID: 65090
Updated by: ab@php.net
Reported by: rgrove at smugmug dot com
Summary: array_multisort() with SORT_NATURAL | SORT_FLAG_CASE
results in incorrect order
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: Linux 2.6.18-194.3.1.el5
PHP Version: 5.4.16
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
That flag combination is exactly what natcasesort() is supposed to do. That means
the behavior is totally correct. Unless you don't need case folding, just remove
SORT_FLAG_CASE.
Previous Comments:
------------------------------------------------------------------------
[2013-06-21 18:50:52] rgrove at smugmug dot com
Description:
------------
When the SORT_NATURAL | SORT_FLAG_CASE flags are passed to array_multisort(), it
sorts strings beginning with the letter "a" above strings beginning with "_",
even
though "_" has a lower ordinal value.
natsort() places "_" before "a" as I would expect, and array_multisort() places
"_" before "a" when given only the SORT_NATURAL flag, without ORing it with
SORT_FLAG_CASE.
See the test script for details.
Test script:
---------------
<?php
$keys = ["_", "a"];
$values = ["first", "second"];
// Results in incorrect order.
array_multisort($keys, SORT_NATURAL | SORT_FLAG_CASE, $values, SORT_ASC);
print_r($keys);
print_r($values);
// Results in correct order.
natsort($keys);
print_r($keys);
// Results in correct order.
array_multisort($keys, SORT_NATURAL, $values, SORT_ASC);
print_r($keys);
?>
Expected result:
----------------
I expect "_" to be sorted before "a", just as natsort() does.
Actual result:
--------------
"a" is sorted before "_".
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65090&edit=1