[英]PHP Warning: Division by zero in
function fctdeux(string $str)
{
$nbr;
$nbr = 0;
while($str >= '0' && $str <= '9')
{
$nbr = $nbr * 10 + ($str - '0');
$str++;
}
return $nbr;
}
function testeur(string $expr)
{
$nbr;
$nbr2;
$op;
$nbr = anal_number($expr);
while($expr)
{
while($expr == ' ')
{
$expr++ ;
$op = $expr;
if($op != '/' && $op != '*' && $op != '%')
return $nbr;
}
$expr++;
$nbr2 = anal_number($expr);
if($op = '/')
{
$nbr /= $nbr2;
}else
if($op == '*')
{
$nbr *= $nbr2;
}else
{
$nbr %= $nbr2;
}
}
return $nbr;
}
echo eval_expr(2+3);
Hello I try to create a calculator for when call the function in end of code echo exemple(2+3)and in terminal call the file php exemple.php its writing result of calcul(5). 您好,我尝试为在代码echo exemple(2 + 3)末尾调用该函数并在终端调用php exemple.php文件时创建计算器的计算器计算结果calcul(5)。 I have this error :
我有这个错误:
PHP Warning: Division by zero in /home/username/project/project.php on line 125
PHP警告:在第125行的/home/username/project/project.php中被零除
its where I have 它在我那里
$nbr /= $nbr2;
in code 在代码中
Division by 0 is impossible. 除以0是不可能的。 How many nothings go into X?
X有多少没有? The answer is a mathematical melt down.
答案是数学上的崩溃。 However, you can catch it in your code:
但是,您可以在代码中捕获它:
if ($nbr2 == 0) {
# code to either return an error message about using 0 to divide
# or you could return NaN (not a number) as the value.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.