By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,747 Members | 2,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,747 IT Pros & Developers. It's quick & easy.

Converting for loop to foreach

P: 36
Hey guys i posted up to a reply some other detail but the main point of it is to know how if you use foreach ... can u access different arrays ... take

Expand|Select|Wrap|Line Numbers
  1.  for ($i = 1; $i <= count($Hours); $i++) //This is compensation for actual work
  2.         {
  3.         $actualValues[$i] = $Hours[$i] * $Wage[$i];
  4.         $theValue += $actualValues[$i];
  5.     }
  6.  
if you look at http://bytes.com/forum/thread844597.html you will see how i have tried doing it and the reasons behind it...
Oct 13 '08 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Mickey.

Here's what you're looking for:

Expand|Select|Wrap|Line Numbers
  1. foreach( $Hours as $i => $loggedHours )
  2.         {
  3.         $actualValues[$i] = $loggedHours * $Wage[$i];
  4.         $theValue += $actualValues[$i];
  5.     }
  6.  
Oct 13 '08 #2

P: 36
lol its that easy... i actually had something v similar to that but thought it wudnt work cus Wage[$i] wasnt part the for loop...

Well was working away at me program and the only errors i have i think come from the for loops so hopefully when I do this i can be finished with it... then i'll start using it for small programs within work =) This should be fun lol.

Cheers again PBMods!
Oct 13 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.