我想要实现的是显示所有会话时间,并且在所有工作日中都有每个时间,然后每个工作日将显示一个或多个事件(如果有的话)。
我可以得到时间和工作日,但不能得到那些日子的事件。我已经提供了我的数组和代码,看看我能不能得到一些帮助。
我的会话时间
Array
(
[06:00:00] => 06:00:00
[07:00:00] => 07:00:00
[08:00:00] => 08:00:00
[09:00:00] => 09:00:00
[09:30:00] => 09:30:00
[17:30:00] => 17:30:00
[18:00:00] => 18:00:00
[18:30:00] => 18:30:00
[19:30:00] => 19:30:00
)
我的活动
Array
(
[0] => stdClass Object
(
[class_id] => 1
[class_name] => Fit Box
[class_description] => Fitbox is a high energy aerobic workout utilizing focus pads, kick pads, heavy bags, and speed balls. This class increases muscle strength and cardiovascular fitness and also includes strength and endurance circuit style training. Excellent for co-ordination, reflexes and to pump out the adrenalin! The class is 1 hour in duration.
[class_time] => 06:00:00
[class_day] => Tuesday
[class_status] => active
[class_colour] => blue
)
[1] => stdClass Object
(
[class_id] => 2
[class_name] => Hot Boxing
[class_description] => test description
[class_time] => 08:00:00
[class_day] => Wednesday
[class_status] => active
[class_colour] => grey
)
[2] => stdClass Object
(
[class_id] => 3
[class_name] => Punch Face
[class_description] => test again
[class_time] => 09:00:00
[class_day] => Thursday
[class_status] => active
[class_colour] => grey
)
[3] => stdClass Object
(
[class_id] => 4
[class_name] => MOS
[class_description] => test again
[class_time] => 19:30:00
[class_day] => Monday
[class_status] => active
[class_colour] => yellow
)
[4] => stdClass Object
(
[class_id] => 5
[class_name] => Yoga
[class_description] => test description
[class_time] => 08:00:00
[class_day] => Wednesday
[class_status] => active
[class_colour] => grey
)
)
这是我试图完成这项工作的代码。
$result_array = array();
$days_array = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
foreach($timetable_times as $time_key => $time_value)
{
// initialize all the days of the week for each time entry
$result_array[$time_value['time']] = array();
foreach($days_array as $day) {
$result_array[$time_value['time']][$day] = "";
}
if (array_key_exists($day, $timetable_classes)) {
$event_entry = $timetable_classes[$time_value['time']];
foreach($event_entry as $event_day => $events) {
$result_array[$time_value['time']][$day][] = $events;
}
}
}
print_r($result_array);
我很感激帮助。
这就是我想要的结果
$arr = array(
"06:00:00" => array(
"Sunday" => array(
array(
'event_title' => "item_1",
'event_desc' => "item_1",
'event_link' => "item_1",
),
),
"Monday" => array(
array(
'event_title' => "item_1",
'event_desc' => "item_1",
'event_link' => "item_1",
),
array(
'event_title' => "item_1",
'event_desc' => "item_1",
'event_link' => "item_1",
),
),
"Tuesday" => "",
"Wednesday" => "",
"Thursday" => "",
"Friday" => "",
"Saturday" => ""
),
"07:00:00" => array("Sunday" => "", "Monday" => "", "Tuesday" => "", "Wednesday" => "", "Thursday" => "", "Friday" => "", "Saturday" => ""),
"08:00:00" => array("Sunday" => "", "Monday" => "", "Tuesday" => "", "Wednesday" => "", "Thursday" => "", "Friday" => "", "Saturday" => ""),
"09:30:00" => array("Sunday" => "", "Monday" => "", "Tuesday" => "", "Wednesday" => "", "Thursday" => "", "Friday" => "", "Saturday" => ""),
"17:00:00" => array("Sunday" => "", "Monday" => "", "Tuesday" => "", "Wednesday" => "", "Thursday" => "", "Friday" => "", "Saturday" => ""),
);