#1 - If you want to get each multiplication for each value, follow this code:
$qty_test=explode(",",$request->input('qty'));
$ltr = [];
foreach ($part_id as $part_ids) {
$get_ltr = part::where('status',1)->where('part_no',$part_ids)->first();
array_push($ltr, $get_ltr->ltr);
}
$total_ltr = [];
foreach($qty_test as $i=>$val){
array_push($total_ltr, $qty_test[$i] * $ltr[$i]);
}
....
....
#2 - But if you want to sum all values in first array
and multiply it to the sum of values in second array
, follow this code:
$qty_test=explode(",",$request->input('qty'));
$ltr = [];
foreach ($part_id as $part_ids) {
$get_ltr = part::where('status',1)->where('part_no',$part_ids)->first();
array_push($ltr, $get_ltr->ltr);
}
$total_ltr= array_sum($qty_test) * array_sum($ltr);
.
array_sum()
will sum all values in an array, for example
echo array_sum([23,14,45]);
// will return 82 (23 + 14 + 45)
.
For more detail, you can refer to Official PHP Documentation about array_sum()