If you use PHP> = 5.3 (necessary for lambda functions), then the solution to array_reduce will be shorter:
$input = array( array( 'name' => 'item 1', 'quantity' => '2', 'price' => 20.00, ), array( 'name' => 'item 2', 'quantity' => '1', 'price' => 15.00, ), array( 'name' => 'item 3', 'quantity' => '4', 'price' => 2.00, ), ); $total = array_reduce($input, function($subtotal, $row) { return $subtotal + $row['quantity'] * $row['price']; });
source share