473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to define the index of array in foreach loop for add/dividing elements of array

7
hi everyone i fetch the array by using foreach loop now how can i define the index of different elements in array for futher computation like i want the element1 of array 1 to be divided by element1 of array 2 code of for each loop
Expand|Select|Wrap|Line Numbers
  1.  <?php
  2.  
  3. if (isset($_POST['submit'])) {
  4.  
  5.     $data_t1 = $_POST['t1'];
  6.  
  7.     foreach ($data_t1 as $key => $value) {
  8.  
  9.         echo 'T1: ' . $value . '<br />';
  10.         echo 'T2: ' . $_POST['t2'][$key] . '<br />';
  11.           echo 'T3: ' . $_POST['a1'][$key] . '<br />';
  12.         echo 'Username: ' . $_POST['username'][$key] . '<br /><br />';
  13.  
  14.     }
  15.       $data_t2 = $_POST['t2'];
  16.       $data_t3=$_POST['a1'];
  17.       $data_t4=$_POST['username'];
  18.  
  19.  
  20. }
  21. var_dump($data_t1);
  22. var_dump($data_t2);
  23. var_dump($data_t3);
  24. var_dump($data_t4);
  25. ?>
  26.  
now i want these array values to be used for further computation
Expand|Select|Wrap|Line Numbers
  1. echo "Measuring Efficiency ";
  2. echo "<table border='1' align='center'>
  3. <tr>
  4. <th>Inputs</th>
  5. <th>A</th>
  6. <th>B</th>
  7. <th>C</th>
  8. </tr>";
  9.   echo "<tr>";
  10.   foreach($data_t4 as $t4)
  11.   {
  12.   echo $t4;         this display the values of array 4
  13.   }
  14.   foreach($data_t1 as $t1)
  15.   {
  16.   echo $t1;
  17. $r=round(($t1/$t4),2);  
  18. $fr=round(($t1/$t4),2); 
  19. $br=round(($t1/$t4),2); 
  20.  
  21. echo "<td>" ."Room Size/Consumption". "</td>";
  22. echo "<td>".$r. "</td>";
  23. echo "<td>".$fr. "</td>";
  24. echo "<td>".$br. "</td>";
  25.  echo "</tr>";
  26.   echo "<tr>";
  27.   }
  28.  
  29.   ?>
  30.  
how can i define the index of array for division of elements of two array
May 25 '13 #1
0 1147

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

Similar topics

2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
4
by: Jack E Leonard | last post by:
I'm looping through the keys and values of a form submission using foreach($_POST as $key => $value) echo "$key = $value<br>"; No problems there. All works as expected. But seveal of the...
3
by: rhaazy | last post by:
If I want to use a FOREACH loop on an array of strings, but didn't want to include the first member,how would I do this??? Psuedo Code::: foreach(string a in myStringArray (where a.index>0))...
4
by: e_matthes | last post by:
Hello everyone, I have no trouble looping through an array using foreach. To keep track of the index, I set a variable before the loop and increment it in the loop: $index = 0; foreach...
10
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I wanted to go through each entry(?) of ArrayList and remove some particular entry. So I tried following but it throws exception at runtime: foreach (myEntry entry in myArrayList) {...
3
by: cody | last post by:
Currently it is only legal to use types which has a method named GetEnumerator to be used in a foreach loop. This makes it impossible to use the same Enumerator after and before a foreach loop,...
9
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return...
3
by: SM | last post by:
Hello, I have an array that holds images path of cd covers. The array looks like this: $cd = array( 589=>'sylver.jpg', 782=>'bigone.jpg', 158=>'dime.jpg' );
5
by: Ivan S | last post by:
I'm using next snippet: $somearray = array(...); foreach($somearray as $item1) { foreach($item1 as $item2) { // ... do something ... } }
2
by: gomako | last post by:
Hi, I'm new, so please let me know if any of my forum etiquette is wrong! Apologies for the fairly nondescript subject line, but I am being driven insane by it. Anyhow, I have a form with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.