Reputation: 59
i have two arrays and i want to make calculations with the elements in these arrays.
$result1=DB::where('elements',$elements)->get();
$result2=DB::where('otherElements',$otherElements)->get();
for example; $result1 = [5,7,9] and $result2 = [0,5,9]
$result3 must be (for multiply) [0,35,81] or (for sum) [5,12,18]
i tried to do with for loop but it does not solve my problem in blade file.
so i want to do it in controller then send the result to the blade file.
Upvotes: 0
Views: 933
Reputation: 130
Also you can use array_map and array_sum as:
$result1 = [1, 2];
$result2 = [1, 2];
$result3 = array_map(function () {
return array_sum(func_get_args());
}, $result1, $result2);
print_r($result3);
Upvotes: 1