I am not sure if it is a bug or a feature but if I try the following code
This puts out:
However, if I use this array:
I get:
after the sorting.
Suddenly my indexes are gone.
I guess what happens is that they are converted to integers somewhere down the line.
However, it messes up my data because I actually want to have the >>string<< '3' there.
Any suggestions on how to get PHP do this..?!?
I tried single quotes, double quotes, enclosing the keys in a strval(), and casting them explicitly by using (string).
All to no avail...
Code:
$aTest = array( '3 ' => array('a' => '3a',
'b' => '3b'),
'a' => array('a' => 'aa',
'b' => 'ab'),
'5 ' => array('a' => '5a',
'b' => '5b') );
printArr($aTest);
array_multisort(array_keys($aTest), SORT_ASC, SORT_STRING, $aTest);
print "===================================<br>";
printArr($aTest);
function printArr($aArr) {
print "<pre>";
print_r($aArr);
print "</pre>";
}
This puts out:
Code:
Array
(
[3 ] => Array
(
[a] => 3a
[b] => 3b
)
[a] => Array
(
[a] => aa
[b] => ab
)
[5 ] => Array
(
[a] => 5a
[b] => 5b
)
)
===================================
Array
(
[3 ] => Array
(
[a] => 3a
[b] => 3b
)
[5 ] => Array
(
[a] => 5a
[b] => 5b
)
[a] => Array
(
[a] => aa
[b] => ab
)
)
Code:
$aTest = array( '3' => array('a' => '3a',
'b' => '3b'),
'a' => array('a' => 'aa',
'b' => 'ab'),
'5' => array('a' => '5a',
'b' => '5b') );
Code:
Array
(
[0] => Array <-- Where did the '3' go???
(
[a] => 3a
[b] => 3b
)
[1] => Array <-- Where did the '5' go???
(
[a] => 5a
[b] => 5b
)
[a] => Array
(
[a] => aa
[b] => ab
)
)
Suddenly my indexes are gone.
I guess what happens is that they are converted to integers somewhere down the line.
However, it messes up my data because I actually want to have the >>string<< '3' there.
Any suggestions on how to get PHP do this..?!?
I tried single quotes, double quotes, enclosing the keys in a strval(), and casting them explicitly by using (string).
All to no avail...