我有一个问题,两个结果之间是否可能存在差异(数学运算)?
以下是代码:
<?php
$row = $query->row();
echo "<b>Your total expenses:</b><br />". $row->TotalExpense;
?>
<?php
$row = $query2->row();
echo "<b>Your total incomes:</b><br />". $row->TotalIncome;
?>
我可以制作类似的东西: TotalIncome - TotalExpense?
<?php
$x = query2
$y = query1
echo $x - $y;
?>
谢谢!
答案 0 :(得分:1)
<?php
$x = $row->TotalIncome;
$y = $row->TotalExpense;
echo "<b>Balance:</b><br />" . ($x - $y);
?>
答案 1 :(得分:1)
<?php
$query1 = array(
"TotalExpense" => 200.42
);
$query2 = array(
"TotalIncome" => 500.42
);
$row1 = (object)$query1;
echo "<b>Your total expenses:</b>". $row1->TotalExpense ."<br />";
$row2 = (object)$query2;
echo "<b>Your total incomes:</b>". $row2->TotalIncome ."<br />";
echo "<b>Your balance:</b>". ($row2->TotalIncome - $row1->TotalExpense) ."<br />";
此输出中的结果
<b>Your total expenses:</b>200.42<br /><b>Your total incomes:</b>500.42<br /><b>Your balance:</b>300<br />
&#13;
答案 2 :(得分:1)
如果您的起点是正确的。你已经有了它。
<?php
$TotalExpense = $query->row()->TotalExpense;
$TotalIncome = $query2->row()->TotalIncome;
echo "<b>Your Balance:</b><br />". ($TotalIncome - $TotalExpense);
?>