3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $doc=<<<EOT { "status":"ok", "items":[ { "location":{ "name":"South Korea", "address":"", "lat":36, "lng":128, "pk":"108278619196284" } }, { "location":{ "name":"Seoul, South Korea", "address":"", "lat":37.5689, "lng":126.977, "pk":"110272918995512" } }, { "location":{ "name":"Seoul, Korea", "address":"", "lat":37.51502, "lng":127.01648, "pk":"108259475871818" } }, { "location":{ "name":"Busan, South Korea", "address":"", "lat":35.1796, "lng":129.076, "pk":"110643562296368" } }, { "location":{ "name":"Gwangju, South Korea", "address":"", "lat":35.1547, "lng":126.916, "pk":"146676562016844" } }, { "location":{ "name":"Daegu, South Korea", "address":"", "lat":35.8223, "lng":128.6115, "pk":"102159636493202" } }, { "location":{ "name":"Gangwon-do, South Korea", "address":"", "lat":37.7448241535, "lng":128.230475313, "pk":"140680839290948" } }, { "location":{ "name":"HelloKittycafe_sinchon", "address":"\uc11c\ub300\ubb38\uad6c \uba85\ubb3c\uae3836-6", "lat":37.5513676016, "lng":126.922082621, "pk":"1485147221780322" } }, { "location":{ "name":"\uc5d0\ubc84\ub79c\ub4dc (withEverland)", "address":"\uacbd\uae30\ub3c4 \uc6a9\uc778\uc2dc \ucc98\uc778\uad6c \ud3ec\uace1\uc74d \uc5d0\ubc84\ub79c\ub4dc\ub85c 199, \uacbd\uae30\ub3c4 \uc6a9\uc778", "lat":37.2928590281, "lng":127.203179318, "pk":"182698125088068" } }, { "location":{ "name":"\ub3d9\ub300\ubb38\ub514\uc790\uc778\ud50c\ub77c\uc790 DDP", "address":"\uc911\uad6c \uc744\uc9c0\ub85c 281, \uc11c\uc6b8", "lat":37.5670904054, "lng":127.009630198, "pk":"124772757536805" } }, { "location":{ "name":"Gwangju", "address":"", "lat":35.159494, "lng":126.851287, "pk":"103826889656659" } } ] } EOT; $location = []; $doc = json_decode($doc); foreach($doc->items as $item) { if (isset($item->location) && isset($item->location->name)) { //echo "location: {$item->location->name}\n"; $location[$item->location->name] = $item->location; } } unset($item); var_dump($location);
based on iKPk6
Output for 7.0.30 - 7.3.0rc3
array(11) { ["South Korea"]=> object(stdClass)#2 (5) { ["name"]=> string(11) "South Korea" ["address"]=> string(0) "" ["lat"]=> int(36) ["lng"]=> int(128) ["pk"]=> string(15) "108278619196284" } ["Seoul, South Korea"]=> object(stdClass)#4 (5) { ["name"]=> string(18) "Seoul, South Korea" ["address"]=> string(0) "" ["lat"]=> float(37.5689) ["lng"]=> float(126.977) ["pk"]=> string(15) "110272918995512" } ["Seoul, Korea"]=> object(stdClass)#6 (5) { ["name"]=> string(12) "Seoul, Korea" ["address"]=> string(0) "" ["lat"]=> float(37.51502) ["lng"]=> float(127.01648) ["pk"]=> string(15) "108259475871818" } ["Busan, South Korea"]=> object(stdClass)#8 (5) { ["name"]=> string(18) "Busan, South Korea" ["address"]=> string(0) "" ["lat"]=> float(35.1796) ["lng"]=> float(129.076) ["pk"]=> string(15) "110643562296368" } ["Gwangju, South Korea"]=> object(stdClass)#10 (5) { ["name"]=> string(20) "Gwangju, South Korea" ["address"]=> string(0) "" ["lat"]=> float(35.1547) ["lng"]=> float(126.916) ["pk"]=> string(15) "146676562016844" } ["Daegu, South Korea"]=> object(stdClass)#12 (5) { ["name"]=> string(18) "Daegu, South Korea" ["address"]=> string(0) "" ["lat"]=> float(35.8223) ["lng"]=> float(128.6115) ["pk"]=> string(15) "102159636493202" } ["Gangwon-do, South Korea"]=> object(stdClass)#14 (5) { ["name"]=> string(23) "Gangwon-do, South Korea" ["address"]=> string(0) "" ["lat"]=> float(37.7448241535) ["lng"]=> float(128.230475313) ["pk"]=> string(15) "140680839290948" } ["HelloKittycafe_sinchon"]=> object(stdClass)#16 (5) { ["name"]=> string(22) "HelloKittycafe_sinchon" ["address"]=> string(26) "서대문구 명물길36-6" ["lat"]=> float(37.5513676016) ["lng"]=> float(126.922082621) ["pk"]=> string(16) "1485147221780322" } ["에버랜드 (withEverland)"]=> object(stdClass)#18 (5) { ["name"]=> string(27) "에버랜드 (withEverland)" ["address"]=> string(77) "경기도 용인시 처인구 포곡읍 에버랜드로 199, 경기도 용인" ["lat"]=> float(37.2928590281) ["lng"]=> float(127.203179318) ["pk"]=> string(15) "182698125088068" } ["동대문디자인플라자 DDP"]=> object(stdClass)#20 (5) { ["name"]=> string(31) "동대문디자인플라자 DDP" ["address"]=> string(28) "중구 을지로 281, 서울" ["lat"]=> float(37.5670904054) ["lng"]=> float(127.009630198) ["pk"]=> string(15) "124772757536805" } ["Gwangju"]=> object(stdClass)#22 (5) { ["name"]=> string(7) "Gwangju" ["address"]=> string(0) "" ["lat"]=> float(35.159494) ["lng"]=> float(126.851287) ["pk"]=> string(15) "103826889656659" } }
Output for 5.6.30, hhvm-3.18.5 - 3.22.0
array(11) { ["South Korea"]=> object(stdClass)#3 (5) { ["name"]=> string(11) "South Korea" ["address"]=> string(0) "" ["lat"]=> int(36) ["lng"]=> int(128) ["pk"]=> string(15) "108278619196284" } ["Seoul, South Korea"]=> object(stdClass)#5 (5) { ["name"]=> string(18) "Seoul, South Korea" ["address"]=> string(0) "" ["lat"]=> float(37.5689) ["lng"]=> float(126.977) ["pk"]=> string(15) "110272918995512" } ["Seoul, Korea"]=> object(stdClass)#7 (5) { ["name"]=> string(12) "Seoul, Korea" ["address"]=> string(0) "" ["lat"]=> float(37.51502) ["lng"]=> float(127.01648) ["pk"]=> string(15) "108259475871818" } ["Busan, South Korea"]=> object(stdClass)#9 (5) { ["name"]=> string(18) "Busan, South Korea" ["address"]=> string(0) "" ["lat"]=> float(35.1796) ["lng"]=> float(129.076) ["pk"]=> string(15) "110643562296368" } ["Gwangju, South Korea"]=> object(stdClass)#11 (5) { ["name"]=> string(20) "Gwangju, South Korea" ["address"]=> string(0) "" ["lat"]=> float(35.1547) ["lng"]=> float(126.916) ["pk"]=> string(15) "146676562016844" } ["Daegu, South Korea"]=> object(stdClass)#13 (5) { ["name"]=> string(18) "Daegu, South Korea" ["address"]=> string(0) "" ["lat"]=> float(35.8223) ["lng"]=> float(128.6115) ["pk"]=> string(15) "102159636493202" } ["Gangwon-do, South Korea"]=> object(stdClass)#15 (5) { ["name"]=> string(23) "Gangwon-do, South Korea" ["address"]=> string(0) "" ["lat"]=> float(37.7448241535) ["lng"]=> float(128.230475313) ["pk"]=> string(15) "140680839290948" } ["HelloKittycafe_sinchon"]=> object(stdClass)#17 (5) { ["name"]=> string(22) "HelloKittycafe_sinchon" ["address"]=> string(26) "서대문구 명물길36-6" ["lat"]=> float(37.5513676016) ["lng"]=> float(126.922082621) ["pk"]=> string(16) "1485147221780322" } ["에버랜드 (withEverland)"]=> object(stdClass)#19 (5) { ["name"]=> string(27) "에버랜드 (withEverland)" ["address"]=> string(77) "경기도 용인시 처인구 포곡읍 에버랜드로 199, 경기도 용인" ["lat"]=> float(37.2928590281) ["lng"]=> float(127.203179318) ["pk"]=> string(15) "182698125088068" } ["동대문디자인플라자 DDP"]=> object(stdClass)#21 (5) { ["name"]=> string(31) "동대문디자인플라자 DDP" ["address"]=> string(28) "중구 을지로 281, 서울" ["lat"]=> float(37.5670904054) ["lng"]=> float(127.009630198) ["pk"]=> string(15) "124772757536805" } ["Gwangju"]=> object(stdClass)#23 (5) { ["name"]=> string(7) "Gwangju" ["address"]=> string(0) "" ["lat"]=> float(35.159494) ["lng"]=> float(126.851287) ["pk"]=> string(15) "103826889656659" } }