“致命错误:未划分的划分划分:零”。但是变量已添加了值
我在php中制作了2个数组,在此处添加了数组的值
$num_a = array(2,4);
$num_b = array(8,12);
,我在这样的段落中使用foreach循环来计算阵列中的总值其中的数字,
$total_a = 0;
$total_b = 0;
foreach($num_a as $key => $a){
$total_a += $a;
$total_b += $num_b;
}
所以我检查结果,但是有错误的
$result = $total_a/$total_b;
错误是: 致命错误:未划分的划分ByzeroError:第52行中的零分割
我知道错误是因为它不能在值变量中进行零操作,但是在这里我使用foreach循环填充了值,那么它可以如何?以及如何解决这个问题,谢谢...
i make 2 arrays in PHP and i added value in array here
$num_a = array(2,4);
$num_b = array(8,12);
i make a conditional for calculate total value in array like this using foreach loop like this, i declared the total = 0
so that there are no random numbers in it
$total_a = 0;
$total_b = 0;
foreach($num_a as $key => $a){
$total_a += $a;
$total_b += $num_b;
}
so i check the result but it's have an error
$result = $total_a/$total_b;
the error is :Fatal error: Uncaught DivisionByZeroError: Division by zero in line 52
i know the error because it's cannot doing operation zero in value variable, but here i have fill the value using foreach loop, so how it can be? and how to solve this, thank you...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该替换
为
You should replace
by