I have an array that I am creating from a MySql database and encoding in json.
$data_array = array();
while ($row = mysql_fetch_assoc($result)) {
$data_array[$row['city']] = $row['state'];
}
echo json_encode($data_array);
As expected, it is outputting this:
{"DALLAS":"WV","DALLAS CENTER":"IA","DALLAS CITY":"IL","DALLASTOWN":"PA","LAKE DALLAS":"TX"}
I need the json data to look like this:
{"DALLAS, WV","DALLAS CENTER, IA","DALLAS CITY, IL","DALLASTOWN, PA","LAKE DALLAS, TX"}
I can’t seem to find the correct answer to this anywhere on Stack Overflow, so I apologize in advance if this is a repeat question. Any help is greatly appreciated.
Instead of this, as a key-value pair
Generate it like this