嗨,我在PhP中有两个多维数组,我正在尝试创建一个更平坦的新数组。
Array
(
[0] => Array
(
[periodweekno] => 27
)
[1] => Array
(
[periodweekno] => 28
)
[2] => Array
(
[periodweekno] => 29
)
)
第二种叫做预订。这存储了一个孩子在特定的一周被预订的日期。
Array
(
[0] => Array
(
[periodDayName] => Monday
)
[1] => Array
(
[periodDayName] => Tuesday
)
[2] => Array
(
[periodDayName] => Thursday
)
[3] => Array
(
[periodDayName] => Friday
)
)
我正在尝试合并两个数组,并检查perioddayName是否为Monday,然后在“new”合并数组中,我可以将其显示为“Monday”=>0,如果不是,则将其显示为“Monday”=>1。我想在每一个“工作日”(即星期一至星期五)重复一遍。
如果我没有很好地解释,我会提前道歉,但这正是我试图实现的,我可以绑定到一个表的结构:
{Weekno:27, Monday:1,Tuesday:0,Wednedsay:1,Thursday:1,Friday:0
Weekno:28, Monday:0,Tuesday:0,Wednesday:1, Thursday:0,Friday:1}
到目前为止,这是我的尝试,但我无法让它变平:
$result = array();
foreach ($weeksbooked as $week) {
$sql = “SELECT periodDayName FROM Attendance WHERE weekno = “. $week[‘periodweekno’];
$bookings = $this->db->RawQuery($sql,null);
// print_r($bookings);
foreach ($bookings as $booking) {
$daysbooked= array();
if($booking[‘periodDayName’] == ‘Monday’){
$daysbooked[‘monday’] = 0;
}else{
$daysbooked[‘monday’] = 1;
}
if($booking[‘periodDayName’] == ‘Tuesday’){
$daysbooked[‘tuesday’] = 0;
}else{
$daysbooked[‘tuesday’] = 1;
}
…..
array_push($weeksbooked,$daysbooked)
}
array_push($result,$weekbooked)