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 ) ) ) Quote Link to comment 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']; //.... } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.