Welcome to WebmasterWorld Guest from 23.20.147.6

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

foreach multidimension array

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

Junior Member

10+ Year Member

joined:July 17, 2006
posts:137
votes: 0


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
5:03 pm on Jan 12, 2013 (gmt 0)

Junior Member

10+ Year Member

joined:July 17, 2006
posts:137
votes: 0


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>";
}


}

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

Junior Member

5+ Year Member

joined:Nov 16, 2008
posts: 136
votes: 0


i hope you dont have a lot of data in this array because this could be hard on the server
6:40 am on Jan 16, 2013 (gmt 0)

Junior Member

10+ Year Member

joined:July 17, 2006
posts:137
votes: 0


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
1:05 pm on Jan 16, 2013 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 16, 2008
posts: 136
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members