Total price from multidimensional array.

I am currently trying (for the first time) to build a shopping cart.
Most of the cart is complete, except for the total price.

I have a multidimensional array in a session that looks like this.

Array
(
    [23] => Array
        (
            [0] => 23
            [1] => 11.32.097.
            [2] => 635
            [3] => 2
            [4] => 89
        )

    [800] => Array
        (
            [0] => 800
            [1] => 20.40.017.
            [2] => 100
            [3] => 1
            [4] => 125
        )
)

The 4th key contains the price. I want to count all the sub-arrays 4th key value en count them together to get a total prics.
I tried doing this with foreach loop but i’m not a great fan of for loops.

If you have some time can you please take a look at it.

Thanks in advance,

Roy

Phew after some helping i finally got out, thanks to wepnop.
If you have the same problem, here is the solution. ;D

$total = 0;
foreach ($array as $key => $value) {
    $total += $value[4];
}
Sponsor our Newsletter | Privacy Policy | Terms of Service