I am needing to get the sum value of two array variables.
Here's my code:
for($i=0;$i<sizeof($check);$i++){
for($j=0;$j<sizeof($item_rec);$j++){
for($k=0;$k<sizeof($last_item_rec);$k++){
//TOTAL_VAR = $item_rec[$j] + $last_item_rec[$k];
$query=mysqli_query($con,"UPDATE tblstock
SET
rec_qty='{{SUM VALUE HERE}}'
WHERE id = '$check[$i]'")
or die(mysqli_error($con));
}
}
}//end for loop
As you can see in the comment, I don't know what variable will I declare to sum each array value of variable $item_rec and $last_item_rec.
You cannot use $i
variable in all nested for
loops.
Change it to $i
, $j
and $k
, for example.
Hi yes you will need to store the sum of two arrays in an array variable.
This code may help,
for($i=0;$i<sizeof($check);$i++){
for($j=0;$j<sizeof($item_rec);$j++){
for($k=0;$k<sizeof($last_item_rec);$k++){
$TOTAL_VAR = array();
$TOTAL_VAR = (int)$item_rec[$j] + (int)$last_item_rec[$k];
$query=mysqli_query($con,"UPDATE tblstock
SET
rec_qty='$TOTAL_VAR[$i]'
WHERE id = '$check[$i]'")
or die(mysqli_error($con));
}
}
}//end for loop
Let me see if you can get through this.