Q:

How to check if part of an array is true and then return a seperate part of array?

So I have this array:
"address_components" : [
     {
        "long_name" : "#7",
        "short_name" : "#7",
        "types" : [ "subpremise" ]
     },
     {
        "long_name" : "23",
        "short_name" : "23",
        "types" : [ "street_number" ]
     },
     {
        "long_name" : "Bedford Road",
        "short_name" : "Bedford Rd",
        "types" : [ "route" ]
     },
     {
        "long_name" : "Lexington",
        "short_name" : "Lexington",
        "types" : [ "locality", "political" ]
     },
     {
        "long_name" : "California",
        "short_name" : "CA",
        "types" : [ "administrative_area_level_1", "political" ]
     },
     {
        "long_name" : "United States",
        "short_name" : "US",
        "types" : [ "country", "political" ]
     },
     {
        "long_name" : "02435",
        "short_name" : "02435",
        "types" : [ "postal_code" ]
     }
  ],

And this code:
foreach ('address_components' as $type) {
  if ($type['types'] = 'administrative_area_level_1') {
    $state = $type['short_name'];
  }
}

I'm trying to loop through the array and check if the type matches administrative area level 1 and if it does return the value of that part's short name. The code I have so far is only returning the first item in the array.
Thanks.

A:

Your condition is false. Change 
if ($type['types'] = 'administrative_area_level_1') // ....

To
 if ($type['types'] == 'administrative_area_level_1')

Because  if ($type['types'] = 'administrative_area_level_1') is true. 
You set $type['types'] with the value : administrative_area_level_1 so it's normal to return true.

