本文介绍了警告:零除法在PHP和MySQL上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用从mysql提取的数组进行计算,问题是被零除"警告

I am doing a calculation with an array which is drawn from mysql and the problem is "division by zero" warning

我正在对此声明进行循环

I am running a loop over this statment

$v = (($v - $valuei)/($valuei) * 100);

这里$ v正在变化(比如说从100变为150,例如100、101、102、103,...,150),而$ valuei是$ v的初始值(即100).将开始的第一个输出应该为零,我想要那个零,然后为什么要给出警告被零除",并使所有"$ v"值等于零.

Here $v is is changing (let's say from 100 to 150 e.g 100, 101, 102, 103,...,150) and $valuei is the intial value of $v (i.e 100) So, when the calculation will start first output should be zero and I want that zero then why it gives a warning "Division By Zero " and also makes all the "$v" values equal to zero.

推荐答案

警告提示,在其中一次运行中,$ valuei实际上为0.

The warning suggests, that $valuei is, in fact, 0 during one of the runs.

您确定$ valuei已正确初始化吗?要消除警告,您应该添加do:

Are you sure, that $valuei is initialized properly?To get rid of the warning, you should add do:

if($valuei != 0) {
    $v = (($v - $valuei)/($valuei) * '100');
}

这样,警告应该消失.

这篇关于警告:零除法在PHP和MySQL上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:36