I want to add the locality name from a google maps html call(below) to a specific php variable so that I can 1) store it in a mysql database and 2) display it as part of an echo statement (echo $locality).

> 
> <http://maps.googleapis.com/maps/api/geocode/json?latlng=34.11375320612877,-118.35220470764159&sensor=false>
> 
> 
> 

I have decoded the json data via: json\_decode($data,true); statement.

Given the complexity of the multivariable array structure, I'd like to dive down and pull out a specific value if it exists. An example to help explain.

Here is the json data abreviated to save space:

> 
> {
>  "results" : [  
> 
>  {  
> 
>  "address\_components" : [  
> 
>  {  
> 
>  "long\_name" : "2917-2981",  
> 
>  "short\_name" : "2917-2981",  
> 
>  "types" : [ "street\_number" ]  
> 
>  },  
> 
>  {
>  "long\_name" : "Runyon Canyon Rd",  
> 
>  "short\_name" : "Runyon Canyon Rd",  
> 
>  "types" : [ "route" ]  
> 
>  },  
> 
>  {  
> 
>  "long\_name" : "Hollywood Hills",  
> 
>  "short\_name" : "Hollywood Hills",  
> 
>  "types" : [ "neighborhood", "political" ]  
> 
>  },  
> 
>  {  
> 
>  "**long\_name" : "Los Angeles"**,  
> 
>  "short\_name" : "Los Angeles",  
> 
> **"types" : [ "locality"**, "political" ]  
> 
>  }  
> 
>  ....
> 
> 
> 

my code:

> 
> ...  
> 
>  $data = @file\_get\_contents($url);  
> 
>  $phpresult = json\_decode($data,true);  
> 
>  var\_dump($phpresult);  
> 
> 
> 
> 

var\_dump($phpresult) displays:

> 
> array(2) { ["results"]=> array(8) { [0]=> array(4) { ["address\_components"]=> array(8) { [0]=> array(3) { ["long\_name"]=> string(9) "2917-2981" ["short\_name"]=> string(9) "2917-2981" ["types"]=> array(1) { [0]=> string(13) "street\_number" } } [1]=> array(3) { ["long\_name"]=> string(16) "Runyon Canyon Rd" ["short\_name"]=> string(16) "Runyon Canyon Rd" ["types"]=> array(1) { [0]=> string(5) "route" } } [2]=> array(3) { ["long\_name"]=> string(15) "Hollywood Hills" ["short\_name"]=> string(15) "Hollywood Hills" ["types"]=> array(2) { [0]=> string(12) "neighborhood" [1]=> string(9) "political" } } **[3]=> array(3) { ["long\_name"]=> string(11) "Los Angeles"** ["short\_name"]=> string(11) "Los Angeles" **["types"]=> array(2) { [0]=> string(8) "locality"** [1]=> string(9) "political" }...<
> 
> 
> 

I'd like to store the value "Los Angeles" in variable $locality by searching/parsing/? the array for the condition "type = locality".

I do not want find the information by using the code:

> 
> echo $phpresult['results'][0]['address\_components'][3]['long\_name'];
> 
> 
> 

because that assumes the variable is always 1) in the same location within the array and 2) that it exists.

Any help would be really appreciated. I haven't found an answer and have probably read (but not totally understood) every post relating to the subject.

Thanks in advance for your help.

Shaun