counting session units from array PHP
<p>I want to count my $_SESSION['cart'] (units) products from my basket. </p>

<pre><code>#check added stock
            $units = (int) $_POST['units'];
        $sizes_id = (int) $_POST['size_id'];

        $in_stock = $db-&gt;GetScalar("SELECT p.units FROM products_sizes s 
                                    INNER JOIN products p ON p.product_id = s.product_id
                                    WHERE s.id = '$sizes_id' LIMIT 1");

        $total = isset($_SESSION['cart'][$sizes_id]) ? $_SESSION['cart'][$sizes_id]['units'] : 0;
        $total += $units;

        if($total &lt;= $in_stock) {
            if(isset($_SESSION['cart'][$sizes_id])) {
                $_SESSION['cart'][$sizes_id]['units'] = $total;
            } else {
                $_SESSION['cart'][$sizes_id] = array('size' =&gt; $sizes_id, 'units' =&gt; $total);
            }
            $msg = 'Added';
            $status = 1;
        }else {
            $msg = 'Product is not in the basket';
            $status = 0;
        }
</code></pre>

<p>This is how the output looks like</p>

<pre><code>Array(

[57] =&gt; Array
    (
        [size] =&gt; 57
        [units] =&gt; 5
    )

[56] =&gt; Array
    (
        [size] =&gt; 56
        [units] =&gt; 1
   )
</code></pre>

<p><code>)</code></p>
