What I ultimately want to do is create an api in the format of a json object and pass it along to the front end. And the data is the result of MySQL query.I want to have the structure as this json:
I’ve tried this code
if($num>0){
// cityinfo array
$city_arr=array();
$city_arr["records"]=array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$row['timeline']['cases']
[$row['Date']] = [$row[`NewCases`]];
extract($row);
$city_item=array(
"CityName" => $CityName,
[$row['Date']] = [$row[`NewCases`]],
);
array_push($city_arr["records"], $city_item);
}
but it returns