From:             rgrove at smugmug dot com
Operating system: Linux 2.6.18-194.3.1.el5
PHP version:      5.4.16
Package:          Arrays related
Bug Type:         Bug
Bug description:array_multisort() with SORT_NATURAL | SORT_FLAG_CASE results in 
incorrect order

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 bug report at https://bugs.php.net/bug.php?id=65090&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=65090&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=65090&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=65090&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=65090&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=65090&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=65090&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=65090&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=65090&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=65090&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=65090&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=65090&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=65090&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=65090&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65090&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=65090&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=65090&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=65090&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65090&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=65090&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=65090&r=mysqlcfg

Reply via email to