First I generate an array of 3 positions with random numbers, then I try to subtract the three values from the array. The problem is that if the first subtraction gives me a negative number the next value does not subtract it well.
For example:
$ given = [6,4,4]
The subtraction would be: 6-4-4 = -2
But when I execute it, subtraction gives me: 6
My code:
for($i=0;$i<=2;$i++){
$dado[]=rand(1,6);
echo $dado[$i].' | ';
}
$resta=0;
for($i=0;$i<=2;$i++){
if($dado[$i]>=0){
$resta=$dado[$i]-$resta;
}elseif($dado[$i]<0){
$resta=$dado[$i]+$resta;
}
}