I have a multidimensional array as follows:
Array(
[0] => Array
(
[name] => item 1
[quantity] => 2
[price] => 20.00
)
[1] => Array
(
[name] => item 2
[quantity] => 1
[price] => 15.00
)
[2] => Array
(
[name] => item 3
[quantity] => 4
[price] => 2.00
)
)
I need the 'grand total' of all these items. Now clearly I could get these by doing the following:
$grand_total = 0;
foreach ($myarray as $item) {
$grand_total += $item['price'] * $item['quantity'];
}
echo $grand_total;
My question is - can this be done in less lines of code using any of the array functions in PHP?