How in php to deduce values ​​with a certain key? Here is an example of an array part:

object(stdClass)#1 (9) { ["success"]=> bool(true) ["data"]=> array(1036) { [0]=> object(stdClass)#2 (13) { ["Description"]=> string(16) "Авангард" ["DescriptionRu"]=> string(16) "Авангард" ["Ref"]=> string(36) "8e1718f5-1972-11e5-add9-005056887b8d" ["Delivery1"]=> string(1) "1" ["Delivery2"]=> string(1) "1" ["Delivery3"]=> string(1) "1" ["Delivery4"]=> string(1) "1" ["Delivery5"]=> string(1) "1" ["Delivery6"]=> string(1) "0" ["Delivery7"]=> string(1) "0" ["Area"]=> string(36) "71508136-9b87-11de-822f-000c2965ae0e" ["Conglomerates"]=> NULL ["CityID"]=> string(4) "1042" } [1]=> object(stdClass)#3 (13) { ["Description"]=> string(22) "Авіаторське" ["DescriptionRu"]=> string(22) "Авиаторское" ["Ref"]=> string(36) "d30a9675-7404-11e5-8d8d-005056887b8d" ["Delivery1"]=> string(1) "1" ["Delivery2"]=> string(1) "1" ["Delivery3"]=> string(1) "1" ["Delivery4"]=> string(1) "1" ["Delivery5"]=> string(1) "1" ["Delivery6"]=> string(1) "0" ["Delivery7"]=> string(1) "0" ["Area"]=> string(36) "7150812b-9b87-11de-822f-000c2965ae0e" ["Conglomerates"]=> NULL ["CityID"]=> string(4) "1140" } 

. Thank you in advance!

  • Need to get the city - Alexander Suetin

1 answer 1

I didn’t peer into the code much, so I’ll show you by my example. There is the following array: $arr = ['key1' => 1, 'key2' => 'tralala', 'fruit' => orange]; For example, we want to select a value from the arrays with the key key2: $var = null; foreach ($arr as $key => $value) { if ($key == 'key2') { $var = $value } } $var = null; foreach ($arr as $key => $value) { if ($key == 'key2') { $var = $value } }