title: PHP count total quantity in cart
body: <p>I have <code>$_SESSION['products']</code> to saved multiple cart items, I want to have total quantity to be show up on header</p>
  
  <p>I try to get total quantity with below script:</p>
  
  <pre><code>  if(isset($_SESSION['products'])) {
  
        $totalQty = 0;
  
        foreach($_SESSION['products'] as $itemQty){
            $totalQty += $itemQty;
        }
  
    }
  
    echo $totalquantity;
  </code></pre>
  
  <p>I <code>print_r($_SESSION['products'])</code> get current items in cart below:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
      (
           [p_id] =&gt; 31 
           [p_name] =&gt; Product 31
           [p_price] =&gt; 28.80
           [p_qty] =&gt; 2
      )
  
      [1] =&gt; Array
      (
           [p_id] =&gt; 46 
           [p_name] =&gt; Product 46
           [p_price] =&gt; 18.00
           [p_qty] =&gt; 3
      )
  
      [2] =&gt; Array
      (
           [p_id] =&gt; 12 
           [p_name] =&gt; Product 12
           [p_price] =&gt; 63.00
           [p_qty] =&gt; 1
      )
  )
  </code></pre>
  
  <p>How to loop through an $_SESSION and get a total [p_qty] in an array dynamically?  </p>