From:             
Operating system: Windows
PHP version:      5.4SVN-2012-01-19 (snap)
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:array_multisort converts "digit only" string keys to default 
numeric keys:0,1..

Description:
------------
Hello,
  I think I found a bug in array_multisort, when trying to sort a
multi-dimensional array, which has string keys containing only digits.
On the resulting array, those keys are suppressed, and replaced by '0' for
the first one, '1' for the second...

I had this error on PHP version 5.3.6, and on the last PHP 5.4 Snap
revision: 322462, downloaded from php.net (tested with no .ini file)

Test script:
---------------
$t = array(
    'AZE' => array('SORT' => 'order #2', 'FOO' => 'xx'),
    '123' => array('SORT' => 'order #3', 'FOO' => 'xx'),
    'RTY' => array('SORT' => 'order #5', 'FOO' => 'xx'),
    '654' => array('SORT' => 'order #1', 'FOO' => 'xx'),
    'UIO' => array('SORT' => 'order #4', 'FOO' => 'xx'),
);
$W_ORDER = array();
foreach($t as $key => $row)
    $W_ORDER[(string)$key] = $row['SORT'];

array_multisort(
    $W_ORDER, SORT_ASC, SORT_STRING,
    $t
);
print_r($t);

Expected result:
----------------
Array
(
    [654] => Array
        (
            [SORT] => order #1
            [FOO] => xx
        )

    [AZE] => Array
        (
            [SORT] => order #2
            [FOO] => xx
        )

    [123] => Array
        (
            [SORT] => order #3
            [FOO] => xx
        )

    [UIO] => Array
        (
            [SORT] => order #4
            [FOO] => xx
        )

    [RTY] => Array
        (
            [SORT] => order #5
            [FOO] => xx
        )
)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [SORT] => order #1
            [FOO] => xx
        )

    [AZE] => Array
        (
            [SORT] => order #2
            [FOO] => xx
        )

    [1] => Array
        (
            [SORT] => order #3
            [FOO] => xx
        )

    [UIO] => Array
        (
            [SORT] => order #4
            [FOO] => xx
        )

    [RTY] => Array
        (
            [SORT] => order #5
            [FOO] => xx
        )
)

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

Reply via email to