我正在比较 2 个数组,但在应用 array_diff 后,它以对象形式返回结果。看看下面的代码和结果
<?php
$schedule = ['Monday'=>['12:00','01:20'],'Tuesday'=>['04:00','12:00','20:00']];
$booked_slots = ['Monday'=>['12:00'],'Tuesday'=>['20:00']];
$diff = [];
foreach ($schedule as $day => $times) {
$day_wise_slots = isset($booked_slots[$day]) ? $booked_slots[$day] : [];
$diff[$day] = array_diff($times, $day_wise_slots);
}
echo json_encode($diff);
?>
结果:{"星期一":{"1":"01:20"},"星期二":["04:00","12:00"]}
所需输出:{“星期一”:[“01:20”],“星期二”:[“04:00”,“12:00”]}
慕田峪7331174