Jump to content

Extracting Subarray from a Multidimensional Array


mlmurrah

Recommended Posts

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

                )

 

        )

 

)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.