title: PHP foreach not working with sub-array
body: <p>I need to work out how to do I get the following to work.</p>
  
  <p>I have an array with sub-array</p>
  
  <pre><code>array (
    'session' =&gt; '1359964785.85203874781',
    'status' =&gt; 'cart',
    'items' =&gt; 
    array (
      'id' =&gt; '510bca8138fc5d6e38000000',
      'quantity' =&gt; '1',
    ),
  )
  </code></pre>
  
  <p>then when I put that array thought my foreach</p>
  
  <pre><code>&lt;?php
         $cart = Shop::get_cart();
         ;
              if($cart != NULL)
              { 
                  foreach($cart[0]['items'] as $items)
                  {
                      print $items['id'];
                  ?&gt;
                  &lt;tr&gt;
  
                  &lt;/tr&gt;
                  &lt;?php
                  }   
              }
         ?&gt;
  </code></pre>
  
  <p>I can't seem to access the sub array for items. What I want to be able to do is call it like </p>
  
  <pre><code>$items["id"];
  $items["quantity"];
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I am getting the data from MongoDB by the following code</p>
  
  <pre><code>public function get_cart()
      {
          $collection = static::db()-&gt;redi_shop_orders;
          $cursor = $collection-&gt;find(array('session' =&gt; $_SESSION["redi-Shop"]));
          if ($cursor-&gt;count() &gt; 0)
          {
              $posts = array();
              // iterate through the results
              while( $cursor-&gt;hasNext() ) {   
                  $posts[] = ($cursor-&gt;getNext());
              }
              return $posts;
          }
      }
  </code></pre>
  
  <p>which when I do a print out returns</p>
  
  <pre><code>Array ( [0] =&gt; Array ( [_id] =&gt; MongoId Object ( [$id] =&gt; 510f8eba38fc5d7d43000000 ) [session] =&gt; 1359964785.85203874781 [status] =&gt; cart [items] =&gt; Array ( [id] =&gt; 510bca8138fc5d6e38000000 [quantity] =&gt; 1 ) ) )
  </code></pre>