大家好,我现在使用 foreach 循环获取数组我如何定义数组中不同元素的索引以进行进一步计算,就像我希望数组 1 的元素 1 除以每个循环的数组 2 代码的元素 1
<?php
if (isset($_POST['submit'])) {
$data_t1 = $_POST['t1'];
foreach ($data_t1 as $key => $value) {
echo 'T1: ' . $value . '<br />';
echo 'T2: ' . $_POST['t2'][$key] . '<br />';
echo 'T3: ' . $_POST['a1'][$key] . '<br />';
echo 'Username: ' . $_POST['username'][$key] . '<br /><br />';
}
$data_t2 = $_POST['t2'];
$data_t3=$_POST['a1'];
$data_t4=$_POST['username'];
}
var_dump($data_t1);
var_dump($data_t2);
var_dump($data_t3);
var_dump($data_t4);
?>
现在我希望将这些数组值用于进一步计算
echo "Measuring Efficiency ";
echo "<table border='1' align='center'>
<tr>
<th>Inputs</th>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>";
echo "<tr>";
foreach($data_t4 as $t4)
{
echo $t4; this display the values of array 4
}
foreach($data_t1 as $t1)
{
echo $t1;
$r=round(($t1/$t4),2);
$fr=round(($t1/$t4),2);
$br=round(($t1/$t4),2);
echo "<td>" ."Room Size/Consumption". "</td>";
echo "<td>".$r. "</td>";
echo "<td>".$fr. "</td>";
echo "<td>".$br. "</td>";
echo "</tr>";
echo "<tr>";
}
?
我如何定义数组的索引以划分两个数组的元素
我的结果是
$data_t1 [12 12] $data_t4 [1.44 4.32] $data_t2 [2 4] $data_t3 [2 3]
我想划分 12/1.44,2/1.44 2/1.44 n 12/4.32 4/4.32 3/4.32
我该怎么做