我有两个数组。第一个数组包含一整天的时间表,包括上午8点到晚上11点59分之间的60分钟的时隙。
0 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "07:00:00"
"to" => "08:00:00"
"status" => "available"
"type" => ""
]
1 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "08:00:00"
"to" => "09:00:00"
"status" => "available"
"type" => ""
]
2 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "09:00:00"
"to" => "10:00:00"
"status" => "available"
"type" => ""
]
3 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "10:00:00"
"to" => "11:00:00"
"status" => "available"
"type" => ""
]
4 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "11:00:00"
"to" => "12:00:00"
"status" => "available"
"type" => ""
]
5 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "12:00:00"
"to" => "13:00:00"
"status" => "available"
"type" => ""
]
6 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "13:00:00"
"to" => "14:00:00"
"status" => "available"
"type" => ""
]我有第二个数组,它包含时间表或预定的插槽。
^ array:8 [▼
0 => array:6 [▼
"student_name" => "Davin Daugherty"
"date" => "2022-11-11"
"from" => "10:00:00"
"to" => "10:30:00"
"status" => "booked"
"type" => "theory"
]
1 => array:5 [▼
"student_name" => ""
"date" => "2022-11-11"
"from" => "10:30:00"
"to" => "11:00:00"
"status" => "not available"
]
2 => array:6 [▼
"student_name" => "Davin Daugherty"
"date" => "2022-11-11"
"from" => "11:00:00"
"to" => "12:00:00"
"status" => "booked"
"type" => "theory"
]
3 => array:6 [▼
"student_name" => "Davin Daugherty"
"date" => "2022-11-11"
"from" => "12:00:00"
"to" => "13:00:00"
"status" => "booked"
"type" => "theory"
]
4 => array:5 [▼
"student_name" => ""
"date" => "2022-11-11"
"from" => "13:00:00"
"to" => "14:00:00"
"status" => "available"
]
5 => array:5 [▼
"student_name" => ""
"date" => "2022-11-11"
"from" => "14:00:00"
"to" => "15:00:00"
"status" => "absent"
]
6 => array:6 [▼
"student_name" => "Davin Daugherty"
"date" => "2022-11-11"
"from" => "15:00:00"
"to" => "16:00:00"
"status" => "booked"
"type" => "theory"
]因此,我想比较一下从第一个数组到第二个数组中的时间' from‘。如果这个类是在10到11之间预订的,那么我想要创建一个新的数组:从已预订的数组中创建一个对象,如果没有预订的类,那么我想要一个来自默认调度数组的对象。
最后,我将有一个包含来自两个数组的数据的数组。
最后的数组应该是这样
0 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "07:00:00"
"to" => "08:00:00"
"status" => "available"
"type" => ""
]
1 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "08:00:00"
"to" => "09:00:00"
"status" => "available"
"type" => ""
]
2 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "09:00:00"
"to" => "10:00:00"
"status" => "available"
"type" => ""
]
3 => array:6 [▼
"student_name" => "Davin Daugherty"
"date" => "2022-11-11"
"from" => "10:00:00"
"to" => "10:30:00"
"status" => "booked"
"type" => "theory
]
4 => array:6 [▼
"student_name" => ""
"date" => "2022-11-11"
"from" => "10:30:00"
"to" => "11:00:00"
"status" => "not available"
]
5 => array:6 [▼
"student_name" => "Davin Daugherty"
"date" => "2022-11-11"
"from" => "11:00:00"
"to" => "12:00:00"
"status" => "booked"
"type" => "theory"
]
5 => array:6 [▼
"student_name" => ""
"date" => "2022-11-06"
"from" => "12:00:00"
"to" => "13:00:00"
"status" => "available"
"type" => ""
]
6 => array:6 [▼
"student_name" => "Alex"
"date" => "2022-11-11"
"from" => "13:00:00"
"to" => "14:00:00"
"status" => "Booked"
"type" => "practical"
]发布于 2022-11-11 06:47:09
你可以这样做
$scheduledClasses = collect($scheduledArray);
$bookedClasses = collect($bookeArray);
$newArray = [];
foreach($scheduledClasses as $secheduledClass){
if($bookedClass->where('from', $scheduledClass->from)->count() >0){
$newArray[] = $bookedClass->where('from', $scheduledClass->from)->first();
}else{
$newArray[] = $scheduledClass;
}https://stackoverflow.com/questions/74398722
复制相似问题