As you can see in the code below, there are two appointments on the 2020-01-13 but they get generated as a separate array. How can I put them both on the same array since they are on the same day? I'm fetching all the information from a database using mysqli but for the sake of this code I'm only printing the necessary. It works but I need to know how to gather the appointments that have the same date in the same array.
php
//declare variable
$result = array();
//iterate
while($schedule = $result_data->fetch_assoc()){
//start time conversion into american time
// 24-hour time to 12-hour time
$start_time =date("g:i a", strtotime($schedule['start_time']));
//end time conversion into american time
$end_time =date("g:i a", strtotime($schedule['end_time']));
$my_schedule_start .= $start_time;
$my_schedule_end .= $end_time;
$schedule_date= $schedule['cleaning_date'];
$result[] = array(
"$schedule_date" => [
"number"=>'1',
"badgeClass"=>'',
"url"=>'url',
"dayEvents"=>[
"title"=>$schedule['first_name'].' '.$schedule['last_name'],
"status"=>$schedule['cleaning_status'],
"time"=>$start_time .' - '.$end_time
]
]
);
}
//send response back to jquery
header('Content-Type: application/json');
echo json_encode($result);
this php prints this
[{"2020-01-15":{
"number":"1",
"badgeClass":"",
"url":"url",
"dayEvents":{
"title":"Jen Doe",
"status":"Booked",
"time":"11:00 am - 12:00 pm"}
}
},
{"2020-01-13":{
"number":"1",
"badgeClass":"",
"url":"url",
"dayEvents":{
"title":"John Doe",
"status":"Booked",
"time":"2:00 pm - 5:00 pm"}
}
},
{"2020-01-13":{
"number":"1",
"badgeClass":"",
"url":"url",
"dayEvents":{
"title":"Alfred Doe",
"status":"Booked",
"time":"11:00 am - 12:00 pm"}
}
}
]
but my desired outcome is this
[{
"2020-01-15": {
"number": "1",
"badgeClass": "",
"url": "url",
"dayEvents": {
"title": "Jen Doe",
"status": "Booked",
"time": "11:00 am - 12:00 pm"
}
}
},
{
"2020-01-13": {
"number": "2",
"badgeClass": "",
"url": "url",
"dayEvents": [{
"title": "John Doe",
"status": "Booked",
"time": "2:00 pm - 5:00 pm"
},
{
"title": "Alfred Doe",
"status": "Booked",
"time": "11:00 am - 12:00 pm"
}
]
}
}
]