I have the following which assigns the values I need to an array in php
$resultsAr[$row['stop_name']][$row['route_long_name']][] = $row['arrival_time'];
However when I convert this to JSON it does not have any keys.
echo json_encode($resultsAr);
e.g.
{
Stop1: {
Destination1: [
"11:13",
"11:25"
],
Destination2: [
"11:15",
"11:27"
],
Destination3: [
"11:14",
"11:23",
"11:26"
]
},
They keys are actually the values. How can I assign key names to the array?
Edited: the required JSON output would be keys with values:
[Stops => all stops] [destinations => destinations] [times => arrival times]
json_encode();worked perfectly fine. The array structure specified, is being represented by the JSON you've sent us. What do you want your output to look like?json_decode($json, true);Also, "Stop1", "Destination1" ect. are your Array "Keys". So your keys are there.