If I have this array:
Array
(
[0] => Array
(
[Price] => 18.00
[Quantity] => 2
)
[1] => Array
(
[Price] => 21.00
[Quantity] => 1
)
)
How can I sum and multiply the value to get 57.00
?
I can sum but not multiply:
echo array_sum(array_column($datas, 'Price'));
Use array_map()
to multiply each price and quantity:
$total = array_sum(array_map(function($item) {
return $item['Price'] * $item['Quantity'];
}, $datas));