Jump to content

stdClass Object Multi Dimensional Array


savagenoob

Recommended Posts

I have a stdClass Object Multi Dimensional Array that I need to dissassemble into variables but dont know how to pull the data. The array looks like this:

stdClass Object ( [results] => Array ( [0] => stdClass Object ( [address_components] => Array ( [0] => stdClass Object ( [long_name] => 1600 [short_name] => 1600 [types] => Array ( [0] => street_number ) ) [1] => stdClass Object ( [long_name] => Pennsylvania Ave NW [short_name] => Pennsylvania Ave NW [types] => Array ( [0] => route ) ) [2] => stdClass Object ( [long_name] => Northwest Washington [short_name] => Northwest Washington [types] => Array ( [0] => neighborhood [1] => political ) ) [3] => stdClass Object ( [long_name] => Washington [short_name] => Washington [types] => Array ( [0] => locality [1] => political ) ) [4] => stdClass Object ( [long_name] => District of Columbia [short_name] => DC [types] => Array ( [0] => administrative_area_level_1 [1] => political ) ) [5] => stdClass Object ( [long_name] => United States [short_name] => US [types] => Array ( [0] => country [1] => political ) ) [6] => stdClass Object ( [long_name] => 20500 [short_name] => 20500 [types] => Array ( [0] => postal_code ) ) ) [formatted_address] => 1600 Pennsylvania Ave NW, Washington, DC 20500, USA [geometry] => stdClass Object ( [location] => stdClass Object ( [lat] => 38.8987149 [lng] => -77.0376555 ) [location_type] => ROOFTOP [viewport] => stdClass Object ( [northeast] => stdClass Object ( [lat] => 38.900063880291 [lng] => -77.036306519708 ) [southwest] => stdClass Object ( [lat] => 38.897365919709 [lng] => -77.039004480291 ) ) ) [partial_match] => 1 [types] => Array ( [0] => street_address ) ) ) [status] => OK )

Really I need to start with pulling the lat and lng from the location. No clue how to get to this data.

Link to comment
Share on other sites

The location would be...

$obj->results[0]->geometry->location

 

Which would contain

stdClass Object (
[lat] => 38.8987149 
[lng] => -77.0376555
)

 

Also, here's a formatted version of that mess you posted. Maybe it will help you see the flow of logic easier.

stdClass Object ( 
[results] => Array ( 
	[0] => stdClass Object ( 
		[address_components] => Array ( 
			[0] => stdClass Object ( 
				[long_name] => 1600
				[short_name] => 1600
				[types] => Array ( 
					[0] => street_number
				)
			)
			[1] => stdClass Object (
				[long_name] => Pennsylvania Ave NW
				[short_name] => Pennsylvania Ave NW
				[types] => Array (
					[0] => route
				)
			)
			[2] => stdClass Object (
				[long_name] => Northwest Washington
				[short_name] => Northwest Washington
				[types] => Array (
					[0] => neighborhood
					[1] => political
				)
			)
			[3] => stdClass Object (
				[long_name] => Washington
				[short_name] => Washington
				[types] => Array (
					[0] => locality
					[1] => political
				)
			)
			[4] => stdClass Object (
				[long_name] => District of Columbia
				[short_name] => DC
				[types] => Array (
					[0] => administrative_area_level_1
					[1] => political
				)
			)
			[5] => stdClass Object (
				[long_name] => United States
				[short_name] => US
				[types] => Array (
					[0] => country
					[1] => political
				)
			)
			[6] => stdClass Object (
				[long_name] => 20500
				[short_name] => 20500
				[types] => Array (
					[0] => postal_code
				)
			)
		)
		[formatted_address] => 1600 Pennsylvania Ave NW, Washington, DC 20500, USA
		[geometry] => stdClass Object (
			[location] => stdClass Object (
				[lat] => 38.8987149 
				[lng] => -77.0376555
			)
			[location_type] => ROOFTOP
			[viewport] => stdClass Object (
				[northeast] => stdClass Object (
					[lat] => 38.900063880291
					[lng] => -77.036306519708
				)
				[southwest] => stdClass Object (
					[lat] => 38.897365919709
					[lng] => -77.039004480291
				)
			)
		)
		[partial_match] => 1
		[types] => Array (
			[0] => street_address
		)
	)
)
[status] => OK
)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.