I have an associative array, where the keys are datetime type data (with an interval of 15 minutes)
array:37 [▼
"09:00" => Appointment {
#attributes: array:10 [▼
"id" => 1135
"startDateTime" => "2019-11-19 09:00:00"
"endDateTime" => "2019-11-19 09:45:00"
"duration" => 45
]
}
"09:15" => "" // I want to delete this row -> 15 minutes
"09:30" => "" // I want to delete this row -> 30 minutes end of the appointment
"09:45" => ""
"10:00" => Appointment {...duration => 60 ...}
"10:15" => "" // I want to delete this row -> 15 minutes
"10:30" => "" // I want to delete this row -> 30 minutes
"10:45" => "" // I want to delete this row -> 45 minutes
"11:00" => "" // I want to delete this row -> 60 minutes end of the appointment
"11:15" => ""
"11:30" => ""
"11:45" => "" Appointment {...duration => 15 ...}
...
]
This array will feed a table, so I want to delete the subsequent rows based on the duration of each appointment. I need it because i want to span the appointment over several rows with:
<td class="the-appointment" rowspan="{{ $appointment->duration / 15 }}">...
therefore I need to eliminate the subsequent rows from the array.
I did this:
$index = -1;
foreach ($row as $key => $appointment) {
if ($appointment) {
$loops = $appointment->duration / 15;
}
for ($i = 1; $i < $loops; $i++) {
unset($row[$index + 1]);
$index++;
}
}
array_push($calendar, $row);
But since it is an associative array, I can not get the index of the loop. Is there any cleverer way to do this?
array_keysand use these keys as values.array_spliceis another solution, no keys needed.