This question already has an answer here:
- json_encode not preserving order 2 answers
I have a associative array
Array(
[289] => Array(
'name'=> 'One'
),
[292] => Array(
'name'=> 'One'
),
[290] => Array(
'name'=> 'One'
)
)
After i use json_encode on this array. The keys are sorted, although i get it as JSON object.
Is there way to prevent this behaviour?
Try this:
it should work, at-least helps me !
See this for a related question: How do you stop Chrome and Opera sorting JSON objects by Index ASC?
note: we're talking about a PHP function, but the result is basically javascript, so the statement about the non-existing standard applies as well.
btw: I have tested it with the following code. PHP itself doesnt seem to sort the array, firefox doesn't as well (according to the firebug console).