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

                )

 

        )

 

)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.