homepage Welcome to WebmasterWorld Guest from 54.226.192.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
foreach multidimension array
ahmed24

5+ Year Member



 
Msg#: 4535503 posted 3:47 pm on Jan 12, 2013 (gmt 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

 

ahmed24

5+ Year Member



 
Msg#: 4535503 posted 5:03 pm on Jan 12, 2013 (gmt 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>";
}


}


skoff

5+ Year Member



 
Msg#: 4535503 posted 6:00 pm on Jan 15, 2013 (gmt 0)

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

ahmed24

5+ Year Member



 
Msg#: 4535503 posted 6:40 am on Jan 16, 2013 (gmt 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

skoff

5+ Year Member



 
Msg#: 4535503 posted 1:05 pm on Jan 16, 2013 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved