我有 2 個(gè)兩個(gè)數(shù)組$schedule = [ "Monday" => [0 => "12:00", 1 => "01:20"], "Tuesday" => [0 => "04:20",1 => "12:00"],];$bookedSlots = [ ["Monday" => "01:20"], ["Tuesday" => "04:20" ] ];現(xiàn)在我想要答案或結(jié)果返回剩余可用時(shí)段的數(shù)組,其中應(yīng)從計(jì)劃中刪除預(yù)訂的時(shí)段。就像下面給出的結(jié)果。$availableSlots = $schedule - $bookedSlots; // [ "Monday" => [ 0 => "12:00"], "Tuesday" =>[ 0 => "12:00" ];
1 回答

開滿天機(jī)
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
好的。所以在這里我寫了一個(gè)輔助函數(shù)來概括解決方案。您可以使用下面提到的功能。
function find_diff($schedule, $booked_slots)
{
? $diff = [];
? foreach ($schedule as $day =>? $times) {
? ? $day_wise_slots = isset($booked_slots[$day]) ? $booked_slots[$day] : [];
? ? if (!is_array($day_wise_slots)) $day_wise_slots = [$day_wise_slots];
? ? $diff[$day] = array_diff($times, $day_wise_slots);
? }
? return $diff;
}
使用的函數(shù):isset和array_diff。
- 1 回答
- 0 關(guān)注
- 134 瀏覽
添加回答
舉報(bào)
0/150
提交
取消