View Full Version : About foreach loop
01-03-2006, 08:29 PM
can i use 2 arrays in one foreach loop? i mean something like this ;
foreach($grades as $grade and $courses as $course)
01-03-2006, 08:44 PM
As far as I know, no.
01-03-2006, 09:00 PM
while (list(, $grade) = each($grades) && list(, $course) = each($courses))
Would do what you're trying to do.
ralph l mayo
01-04-2006, 12:44 AM
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
foreach ($grades as $key=>$grade)
// $class' corresponding element to the current $grade is $class[$key]
$keys = count($grades);
for ($ii = 0; $ii < $keys; ++$ii)
// corresponding elements are $grades[$ii] and $class[$ii]
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.