$number1 = 56;
$number2 = 70;
$number3 = 12.56;
echo "Addition of $number1 and $number2 : " . $number1 + $number2 ;
echo "<br>";
echo "Subtraction of $number2 from $number1 but with absolute function: " . abs ($number-$number2) . "<br>";
当我刷新页面时,它给出错误“遇到非数值”的任何帮助
答案 0 :(得分:1)
因为$number
未定义。如下定义
$number1 = 56;
$number2 = 70;
$number3 = 12.56;
$number = $number1 + $number2; //define $number
echo "Addition of $number1 and $number2 : " . $number ;
echo "<br>";
echo "Subtraction of $number2 from $number but with absolute function: " . abs ($number-$number2) . "<br>";
或如下更改代码 :
$number1 = 56;
$number2 = 70;
$number3 = 12.56;
echo "Addition of $number1 and $number2 : " . ($number1 + $number2) ; //bracket added
echo "<br>";
//use predefined variable instead of $number
echo "Subtraction of $number2 from $number1 but with absolute function: " . abs ($number1-$number2) . "<br>";
答案 1 :(得分:1)
根据我的评论(您未定义$number
。应为$number1
,而不是$number
)。此外,按照@nick,添加($number1 + $number2)
$number1 = 56;
$number2 = 70;
$number3 = 12.56;
echo "Addition of $number1 and $number2 : " . ($number1 + $number2) ;
echo "<br>";
echo "Subtraction of $number2 from $number1 but with absolute function: " . abs ($number1-$number2) . "<br>";