Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-03-2006, 08:29 PM   PM User | #1
kesikkafa
New Coder

 
Join Date: Dec 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
kesikkafa is an unknown quantity at this point
About foreach loop

can i use 2 arrays in one foreach loop? i mean something like this ;

Code:
foreach($grades as $grade and $courses as $course) 

{
...
}
kesikkafa is offline   Reply With Quote
Old 01-03-2006, 08:44 PM   PM User | #2
Prikid
New Coder

 
Join Date: Dec 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Prikid is an unknown quantity at this point
As far as I know, no.
Prikid is offline   Reply With Quote
Old 01-03-2006, 09:00 PM   PM User | #3
gsnedders
Senior Coder

 
gsnedders's Avatar
 
Join Date: Jan 2004
Posts: 2,340
Thanks: 1
Thanked 7 Times in 7 Posts
gsnedders will become famous soon enough
PHP Code:
while (list(, $grade) = each($grades) && list(, $course) = each($courses))

{
...

Would do what you're trying to do.
__________________
Geoffrey Sneddon
gsnedders is offline   Reply With Quote
Old 01-04-2006, 12:44 AM   PM User | #4
ralph l mayo
Regular Coder

 
ralph l mayo's Avatar
 
Join Date: Nov 2005
Posts: 951
Thanks: 1
Thanked 31 Times in 29 Posts
ralph l mayo is on a distinguished road
Also if the arrays directly correspond, which I assume they do, since it doesn't make sense to process them concurrently if not, you can do something like

PHP Code:
foreach ($grades as $key=>$grade)
{
    
// $class' corresponding element to the current $grade is $class[$key]

or:

PHP Code:
$keys count($grades);
for (
$ii 0$ii $keys; ++$ii)
{
    
// corresponding elements are $grades[$ii] and $class[$ii]

ralph l mayo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:02 AM.


Advertisement
Log in to turn off these ads.