I have a time array and a event array and i need the 2 to join, could i get some help. So basically the All the times need be there and if there is a match event then it shown and if not nothing.
What i have so far:
Time Array
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 )
Event Array
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 ) )
The Code that aims at displaying all the times and each time has all the days, then each day needs to show events if they have them.
$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);
My desired outcome is below
$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" => ""), );