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);
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.
The warning suggests, that $valuei is, in fact, 0 during one of the runs.
Are you sure, that $valuei is initialized properly?
To get rid of the warning, you should add do:
This way, the warning should disappear.