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
https://forums.phpfreaks.com/topic/238896-echo-variables-in-array/
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

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.