title: Codeigniter - Error while accessing multi dimensional stdObject array
body: <p>I am getting following result array in view from my controller in CodeIgniter:</p>
  
  <pre><code>Array
  (
      [cities] =&gt; Array
      (
          [0] =&gt; stdClass Object
          (
              [id] =&gt; 1
              [name] =&gt; Jersey City
              [state] =&gt; stdClass Object
              (
                  [id] =&gt; 1
                  [name] =&gt; New Jersey             
              )
           )
  
          [1] =&gt; stdClass Object
          (
              [id] =&gt; 2
              [name] =&gt; Philadelphia
              [state] =&gt; stdClass Object
              (
                  [id] =&gt; 2
                  [name] =&gt; Pennsylvania
              )
          )
      )
  )
  </code></pre>
  
  <p>Now I want to create a dropdown box with these values so that the box has city, state.</p>
  
  <pre><code>Jersey, New Jersey
  Philadelphia, Pennsylvania
  </code></pre>
  
  <p>This is how I am trying to achieve this:</p>
  
  <pre><code>&lt;?php 
      foreach($cities as $city) {
          echo "&lt;option value='$city-&gt;id'&gt;$city-&gt;name, $city-&gt;state-&gt;name&lt;/option&gt;";
      }
  ?&gt;
  </code></pre>
  
  <p>When I try to access:</p>
  
  <pre><code>$city-&gt;state-&gt;name
  </code></pre>
  
  <p>I get following error:</p>
  
  <pre><code>&lt;p&gt;Severity: 4096&lt;/p&gt;
  &lt;p&gt;Message: Object of class stdClass could not be converted to string&lt;/p&gt;
  </code></pre>
  
  <p>I would appreciate if someone could guide me the correct way of getting name out of state array.</p>
  
  <p>Thanks!</p>