473,473 Members | 2,153 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Converting for loop to foreach

36 New Member
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
2 1128
pbmods
5,821 Recognized Expert Expert
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
micky125
36 New Member
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

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

Similar topics

5
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality...
13
by: TrintCSD | last post by:
How can I reset the collections within a foreach to be read as a change from within the foreach loop then restart the foreach after collections has been changed? foreach(string invoice in...
5
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
3
by: Akira | last post by:
I noticed that using foreach is much slower than using for-loop, so I want to change our current code from foreach to for-loop. But I can't figure out how. Could someone help me please? Current...
2
by: dkmd_nielsen | last post by:
I have two rather simple class methods coded in Ruby...my own each iterator: The iterator is used internally within the class/namespace, and be available externally. That way I can keep...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.