title: Extract data out of an object array in PHP
body: <p>I have the following array and can't figure out how to get the data out:</p>
  
  <pre><code>Array ( 
     [0] =&gt; stdClass Object ( 
        [address_components] =&gt; Array ( 
           [0] =&gt; stdClass Object ( 
              [long_name] =&gt; 180 
              [short_name] =&gt; 180 
              [types] =&gt; Array ( [0] =&gt; street_number ) 
           ) 
           [1] =&gt; stdClass Object ( 
              [long_name] =&gt; Campus Dr 
              [short_name] =&gt; Campus Dr 
              [types] =&gt; Array ( [0] =&gt; route ) 
           ) 
           [2] =&gt; stdClass Object ( 
              [long_name] =&gt; Arcadia 
              [short_name] =&gt; Arcadia 
              [types] =&gt; Array ( 
                 [0] =&gt; locality 
                 [1] =&gt; political 
              ) 
           ) 
           [3] =&gt; stdClass Object ( 
              [long_name] =&gt; Los Angeles 
              [short_name] =&gt; Los Angeles 
              [types] =&gt; Array ( 
                 [0] =&gt; administrative_area_level_2 
                 [1] =&gt; political 
              )
           ) 
           [4] =&gt; stdClass Object ( 
              [long_name] =&gt; California 
              [short_name] =&gt; CA 
              [types] =&gt; Array ( 
                 [0] =&gt; administrative_area_level_1 
                 [1] =&gt; political 
              ) 
           ) 
           [5] =&gt; stdClass Object ( 
              [long_name] =&gt; United States 
              [short_name] =&gt; US 
              [types] =&gt; Array ( 
                 [0] =&gt; country 
                 [1] =&gt; political 
              ) 
           ) 
           [6] =&gt; stdClass Object ( 
              [long_name] =&gt; 91007 
              [short_name] =&gt; 91007 
              [types] =&gt; Array ( [0] =&gt; postal_code ) 
           ) 
        ) 
        [formatted_address] =&gt; 180 Campus Dr, Arcadia, CA 91007, USA 
        [geometry] =&gt; stdClass Object ( 
           [location] =&gt; stdClass Object ( 
              [lat] =&gt; 34.1301857 
              [lng] =&gt; -118.0333596 
           ) 
           [location_type] =&gt; ROOFTOP 
           [viewport] =&gt; stdClass Object ( 
              [northeast] =&gt; stdClass Object ( 
                 [lat] =&gt; 34.131534680292 
                 [lng] =&gt; -118.03201061971 
              ) 
              [southwest] =&gt; stdClass Object ( 
                 [lat] =&gt; 34.128836719709 
                 [lng] =&gt; -118.03470858029 
              ) 
           ) 
        ) 
        [partial_match] =&gt; 1 
        [types] =&gt; Array ( [0] =&gt; street_address ) 
     ) 
  ) 
  </code></pre>
  
  <p>This is stored in a variable called <code>$results</code></p>
  
  <p>EDIT:
  Although this has already been answered, (thank you), this is what I was attempting:</p>
  
  <pre><code>foreach($results as $key=&gt;$value){
      echo $key.' : '.$value.'&lt;br /&gt;';
  }
  </code></pre>
  
  <p>And it was throwing an error: <code>Object of class stdClass could not be converted to string</code></p>
  
  <p>I knew I was accessing it incorrectly but just couldn't remember what I was doing wrong.</p>