I have two arrays that have values that work together, one with an array of time slots and the other with an array of no of slots per time from left to right. Below is what the arrays look like:
$timeslot = ['22:00', '10:00', '18:00'];
$no_of_slot = [5,10,34];
From about 22:00 = 5
,10:00 = 10
and 18:00 = 34
I was able to sort array $timeslot
so that the array can be in increasing order i.e ````['10:00','18:00','22:00']`` with below code:
function date_compare($element1, $element2) {
$datetime1 = strtotime($element1);
$datetime2 = strtotime($element2);
return $datetime1 - $datetime2;
}
// Sort the array
usort($timeslot, 'date_compare');
But since they work together i.e $timeslot
and $no_of_slot
I will like when the to rearrange is done for $timeslot
then $no_of_slot
should be done too and my final result will be like below:
$timeslot = ['10:00', '18:00', '22:00'];
$no_of_slot = [10,34,5];
Is there a way I can sort them together?