Jump to content

Echo variables in array()


slaterino

Recommended Posts

Hi,

I'm so very close to getting the information I need but just have one final hurdle. I have created an array called $data but just need some help getting the data back out of the array.

 

This is my loop where I am trying to output the data:

 

foreach($data as $date => $v) { 

echo date('D', strtotime($date)) . '<br />'; 
echo date('d', strtotime($date)) . '<br />---------<br />'; 

foreach($v as $event) {

echo $event;

echo "<br />";

}

echo '<br />'; 

}

 

The first loop works fine where I am outputting the dates, but then the $event value is incorrect. At the moment I am simply getting 'Array' for the $event value. However I want to be able to get two values, the ID and the date that are in the array. How do I get this data out of the array? I have been looking at the array() page at php.com for hours trying to work this one out but still can't get there!

 

Here's the result of "print_r($data,true)":

 

Array
(
    [06/09/2011] => Array
        (
            [0] => Array
                (
                    [13] => 06/09/2011
                )

            [1] => Array
                (
                    [15] => 06/08/2011 - 06/10/2011
                )

        )

    [06/10/2011] => Array
        (
            [0] => Array
                (
                    [15] => 06/08/2011 - 06/10/2011
                )

        )

    [06/11/2011] => 
    [06/12/2011] => 
    [06/13/2011] => Array
        (
            [0] => Array
                (
                    [6] => 06/13/2011
                )

        )

    [06/14/2011] => 
    [06/15/2011] => 
)

Link to comment
Share on other sites

looks like you might even need to go one level deeper into your multi dimensional array..try

foreach($data as $date => $v) { 

echo date('D', strtotime($date)) . '<br />'; 
echo date('d', strtotime($date)) . '<br />---------<br />'; 

foreach($v as $event) {

   foreach($event as $key=>$val) {

      //do stuff
   }

}

echo '<br />'; 

}

however, im sure that there is a better solution

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.