[英]Table creation in php and html
I'm basically trying to perform a calculation with the first row and first column however I can't seem to get it working correctly. 我基本上是试图用第一行和第一列执行计算,但是我似乎无法使其正常工作。
function tableCreator($height_arrayy, $weight_arrayy) {
echo "<table><tr><th></th>";
foreach($height_arrayy as $value1) {
echo "<th>$value1</th>";
}
echo "</tr>";
foreach($weight_arrayy as $value2) {
echo "<tr>";
echo "<td>$value2</td>";
foreach($weight_arrayy as $value3) {
foreach($height_arrayy as $value4) {
echo "<td>" . ($value3) / ( pow( ($value4 / 100), 2 ) ) . "</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
Result I am getting: 结果我得到:
Desired Result: 所需结果:
you have added an un-necessary foreach loop, update your second foreach loop as below 您添加了不必要的foreach循环,如下更新第二个foreach循环
foreach($weight_arrayy as $value2) {
echo "<tr>";
echo "<th>$value2</th>";
foreach($height_arrayy as $value4) {
echo "<td>" . ($value2) / ( pow( ($value4 / 100), 2 ) ) . "</td>";
}
echo "</tr>";
}
your code will return desired output. 您的代码将返回所需的输出。 use round() if you want to round upto 2 or 3 decimal points.
如果要舍入到2或3个小数点,请使用round()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.