1
I have a "for" loop in PHP as follows
$max = 10;
for($i = 0; $i <= $max; $i++){
$var1 = $i * 100;
$var2 = var1 * 50;
$var3 = (MINHA_DUVIDA_AQUI);
}
In $var3
I would like to return the value of $var3
of Row previous, for example, if I am in $i = 3
, I need the $var3
be equal to $var2
of $i = 2.
I tried with the function prev()
, but for not being a array didn’t work.
Any tips on how to resolve this situation?
You can make $var2 = ($i-1) * 50. That would be your problem from what I understand.
– Vinicius Gabriel
You only need to treat this situation when $i = 0. In this case I don’t know what you want to return, but you can check if $i == 0 then $var2 = 0, and if it’s not equal 0 calculate according to my comment from above.
– Vinicius Gabriel
The problem is that my "var2" is already the result of another calculation in the previous line
– Vinicius Verner
Just make $var3 = $var2 BEFORE $var2 = formula
– Bacco