I am having a php array which I am encoding using json_encode
as shown below.
PHP Code:
$arr=array(10=>"Apple",1=>"Ball",9=>"Cat",11=>"Dog",15=>"Elephant");
echo json_encode($arr);
The json encoded output maintains the same order as the original array. But when I try to access the json_encode
output in javascript, that object's elements are sorted in increasing numerical index:
console log:
[{1="Ball",9="Cat",10="Apple",11="Dog",15="Elephant"}]
I want to retain the same order as the original array. How can this be done?