title: Printing contents of a nested array
body: <p>I am trying to print the contents of a nested array, but it simply returns "Array" as a string yet will not iterate with a foreach loop. The arrays are coming from a mongodb find(). The dataset looks like this:</p>
  
  <pre><code>User
  Post_Title
  Post_Content[content1,content2,content3]
  </code></pre>
  
  <p>I am trying to get at the content1,2,3.</p>
  
  <p>My current code looks like this:</p>
  
  <pre><code>$results = $collection-&gt;find($query);
  
  foreach ($results as $doc)
      {
      echo $doc['title']; //this works
      $content[] = $doc['content'];           
      print_r($content); //this prints "Array ( [0] =&gt; Array )"
      foreach ($content as $item)
          {
          echo $item;
          }
      }   
  </code></pre>
  
  <p>All this code does is print the Title, followed by Array ( [0] => Array ), followed by Array.</p>
  
  <p>I feel quite stupid to not figure out something that seems so basic. Most posts on stack overflow refer to multidimensional associative arrays - in this case, the top level array is associative, but the content array is indexed.</p>
  
  <p>I have also tried</p>
  
  <pre><code>foreach ($doc['content'] as $item)
  </code></pre>
  
  <p>But that gives</p>
  
  <pre><code>Warning: Invalid argument supplied for foreach() 
  </code></pre>
  
  <p>I even tried iterating over the returned array again using a nested foreach, like the following:</p>
  
  <pre><code>foreach ($results as $doc)
      {
      echo $doc['title']; //this works
      $content[] = $doc['content'];           
      print_r($content); //this prints "Array ( [0] =&gt; Array )"
      foreach ($content as $item)
          {
              foreach ($item as $next_item)
                  {
                    echo $next_item;
                  }
          echo $item;
          }
      }
  </code></pre>
  
  <p>The second foreach failed with an invalid argument.. 
  Any thoughts would be greatly appreciated.</p>
  
  <p>edit: perhaps it has something to do with how I am inserting the data to the DB. That code looks like this</p>
  
  <pre><code>$title = $_POST['list_title'];
  $content[] = $_POST['list_content1'];
  $content[] = $_POST['list_content2'];
  $content[] = $_POST['list_content3'];
  
  $object = new Creation();
  $object-&gt;owner = "$username";
  $object-&gt;title = "$title";
  $object-&gt;content = "$content";
  $object-&gt;insert();
  </code></pre>
  
  <p>Is this not the proper way to add an array as a property to a class?</p>