473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ 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 1133
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
12404
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 provided by Informix. This is the problem: the execution of the translated SQL leaves the rows in the temp table correctly but raises error SQL0480N....
13
14454
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 findListBox.listBox2.Items) { listBox2.Items count changed, restart this foreach } Thanks for any help.
5
23458
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
3
33348
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 code is here: foreach ( string propertyName in ht.Keys ) { this.setProperty( propertyName, ht );
2
2851
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 everything hidden about the "instructions table." # Loop through each instruction in the block, yielding the result from # the specified code block. def...
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.