我编写了一个从while循环返回值的函数。我将此函数调用3次,从而返回3个值。我想总结这些价值观。我的功能代码是
<?php
function CalcTotal($Acc)
{
require('conn_bal.php');
$query = "SELECT Dte, SUM(Cred), SUM(Deb) FROM tbl_account WHERE Acc='$Acc'";
if ($result=mysqli_query($con,$query)) {
$TotBal = 0;
while($row = mysqli_fetch_array($result)){
global $scred, $sdeb;
$scred=$row['SUM(Cred)'];
$sdeb=$row['SUM(Deb)'];
$bal=$scred-$sdeb;
global $TotBal;
$TotBal = number_format($bal, 2);
return $TotBal;
}
}
}
?>
这被称为3个不同的时间,即
<?php
global $green;
$green = CalcTotal("Green");
echo $green;
echo "<br />";
global $blue;
$blue = CalcTotal("Blue");
echo $blue;
echo "<br />";
global $red;
$red = CalcTotal("Red");
echo $red;
echo "<br />";
?>
然后我想添加这3个返回值,即
<?php
global $Total;
$Total = $green + $blue + $red;
echo "Total: $Total";
?>
正在回显正确的值,但$ Total = 3添加代码给出计数,而不是对3个返回的变量求和。
我已经尝试了所有我知道的排列并在互联网上研究过这个问题,但无济于事。
如果有人有任何想法我将如何实现这一点,我将非常感激。
非常感谢