我想要實現的是顯示所有會話時間並且每次都有所有星期幾,然後每個星期一天將顯示一個或多個事件(如果他們有)。PHP陣列合併
我可以得到時間和週日,但不是那些日子的事件。我提供了我的數組和代碼,看看我能否得到一些幫助。
我的會話超時
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" => ""),
);
你在說什麼?這是讓我瘋狂 – James182
你可以嘗試正確縮進你的代碼,使其更具可讀性?不知道爲什麼你會得票。 – 2013-07-12 02:46:52
爲您縮進代碼 – James182