Welcome to WebmasterWorld Guest from 54.144.124.152

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

foreach multidimension array

     

ahmed24

3:47 pm on Jan 12, 2013 (gmt 0)

5+ Year Member



I have an array that is built in the following way:

$event['10-03-2013']['0'] = "Event One";
$event['10-03-2013']['1'] = "Event Two";
$event['10-03-2013']['2'] = "Event Three";
$event['30-10-2013']['0'] = "New Event";

I want to be able to get the date and the description in a foreach loop. Any suggestions how I can do this?

Thanks

ahmed24

5:03 pm on Jan 12, 2013 (gmt 0)

5+ Year Member



nevermind i've figured it out, just nested a loop within a loop like this:



foreach ($event as $eventDate => $eventArray) {

foreach ($eventArray as $eventDescription) {
echo $eventDescription."<br>";
}


}

skoff

6:00 pm on Jan 15, 2013 (gmt 0)

5+ Year Member



i hope you dont have a lot of data in this array because this could be hard on the server

ahmed24

6:40 am on Jan 16, 2013 (gmt 0)

5+ Year Member



skoff, i dont have much data in this array. about 5 - 10 lines max. however, i am using this method of foreach within foreach to work on multiple dimensions. i didnt realise this could be hard on the server. any recommendations how i can do the above without a double foreach loop, instead all in one loop?

thanks

skoff

1:05 pm on Jan 16, 2013 (gmt 0)

5+ Year Member



do you need to loop through all you records in you array or when you get the date you want it stops?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month