I am trying to get a specific json response, but one array in the response is being passed as an object.
"countries":{"TW":8,"JP":5,"AU":6,"MX":12,"CL":4,"HK":2,"US":14,"AR":4,"ES":1,"BR":1,"MY":9,"IT":12,"DE":1,"GB":1,"PE":6,"TR":1,"KR":3,"IE":1,"CA":2,"FR":1,"VE":2,"IL":1,"PT":1,"NL":1,"PL":1}
But I need it to look like this:
"countries":[["Brazil", 40.5],["US", 30],["Canada", 19.5], ["England", 10]]
How do I build that array in PHP for the json_encode response looks like that?
Now I have:
$countries['US']=14;
$countries['CL']=4;
....
Then I add that array ($countries) to the $data array, which is the one json encoded
$data['countries'] = $countries;
Which gives the result I posted first. But I need that in that in the second format.
Anyone knows what am I missing?
Thanks!
1 Answer