I have an array that looks like this, this array represents number of products in a shopping cart
Array
(
[0] => Array
(
[id] => 1
[icon] => bus.png
[name] => Web Development
[cost] => 500
)
[1] => Array
(
[id] => 4
[icon] => icon.png
[name] => Icon design
[cost] => 300
)
[2] => Array
(
[id] => 5
[icon] => icon.png
[name] => footer design
[cost] => 300
)
)
and i am trying to add the [cost]
of each together, since it is a shopping cart I need to display the total. some people might buy single product or 2 or 3 so how do i display the total by adding the cost
together I have tried using array_sum($products['cost'])
and array_sum($products[0]['cost'])
but that does not work