mlmurrah Posted November 25, 2010 Share Posted November 25, 2010 I have a multidimensional array for a calendar application as shown below. The first level is an associative array for calendar dates, and the second is a numeric array for multiple events on each day. The third level holds the events. I know that I can extract a single event using the array indices, such as: echo $events['2010-11-24'][0]['event_date']; If I know the number of events for the date, I can extract them one-by-one by incrementing the array index. However, I never know how many events will be stored for any one day. I also know that I can extract all the data in the entire array using a foreach loop. But how can I extract only the data in a subarray? Array ( [2010-11-16] => Array ( [0] => Array ( [event_date] => 2010-11-16 [title] => Board Meeting ) [1] => Array ( [event_date] => 2010-11-16 [title] => Second event ) ) [2010-11-24] => Array ( [0] => Array ( [event_date] => 2010-11-24 [title] => New meeting ) ) ) Link to comment https://forums.phpfreaks.com/topic/219820-extracting-subarray-from-a-multidimensional-array/ Share on other sites More sharing options...
seanlim Posted November 25, 2010 Share Posted November 25, 2010 if i understand you correctly: foreach($events['2010-11-24'] as $event_id=>$event) { $date = $event['event_date']; $title = $event['title']; //.... } Link to comment https://forums.phpfreaks.com/topic/219820-extracting-subarray-from-a-multidimensional-array/#findComment-1139541 Share on other sites More sharing options...
mlmurrah Posted November 26, 2010 Author Share Posted November 26, 2010 Thanks, that did it. Now to understand it. Link to comment https://forums.phpfreaks.com/topic/219820-extracting-subarray-from-a-multidimensional-array/#findComment-1139959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.