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'));
array_reduce:array_reduce($whatever, function ($a, $e) { return $a + $e['Price'] * $e['Quantity']; }, 0)... Does this answer your question? multidimensional array array_sum. Just add* $e["Quantity"]to just about any answer here; thearray_column/array_sumcombo doesn't work because it doesn't know how to apply multiplication, but anything that has a function body or loop body will give you a chance to apply the desired operation.