Edit report at https://bugs.php.net/bug.php?id=60806&edit=1
ID: 60806 Updated by: ras...@php.net Reported by: jeremie dot legrand at komori-chambon dot fr Summary: array_multisort converts "digit only" string keys to default numeric keys:0,1.. -Status: Open +Status: Bogus Type: Bug Package: Scripting Engine problem Operating System: Windows PHP Version: 5.4SVN-2012-01-19 (snap) Block user comment: N Private report: N New Comment: This is working as documented. The docs state that "numeric keys" will be re- indexed. A string containing just a number is a numeric key. Note it doesn't say integer keys. Previous Comments: ------------------------------------------------------------------------ [2012-01-19 15:04:00] jeremie dot legrand at komori-chambon dot fr 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 this bug report at https://bugs.php.net/bug.php?id=60806&edit=1