PHP multi-dimensional array search for keys and display values -
PHP multi-dimensional array search for keys and display values -
below result of array want grab coordinates , store them in 1 dimensional array.
array ( [name] => jackson [status] => array ( [code] => 200 [request] => geocode ) [placemark] => array ( [0] => array ( [@attributes] => array ( [id] => p1 ) [address] => jackson, ms, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => ms [subadministrativearea] => array ( [subadministrativeareaname] => hinds [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 32.3741783 [south] => 32.2232735 [east] => -90.0567509 [west] => -90.3128697 ) ) ) [point] => array ( [coordinates] => -90.1848103,32.2987573,0 ) ) [1] => array ( [@attributes] => array ( [id] => p2 ) [address] => jackson, tn, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => tn [subadministrativearea] => array ( [subadministrativeareaname] => madison [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 35.7562880 [south] => 35.5402259 [east] => -88.7567579 [west] => -88.9204599 ) ) ) [point] => array ( [coordinates] => -88.8139469,35.6145169,0 ) ) [2] => array ( [@attributes] => array ( [id] => p3 ) [address] => jackson, wy, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => wy [subadministrativearea] => array ( [subadministrativeareaname] => teton [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 43.4912050 [south] => 43.4578330 [east] => -110.7377220 [west] => -110.8134730 ) ) ) [point] => array ( [coordinates] => -110.7624282,43.4799291,0 ) ) [3] => array ( [@attributes] => array ( [id] => p4 ) [address] => jackson, nj, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => nj [subadministrativearea] => array ( [subadministrativeareaname] => ocean [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 40.1723549 [south] => 39.9990330 [east] => -74.2415390 [west] => -74.4695430 ) ) ) [point] => array ( [coordinates] => -74.3294444,40.1080556,0 ) ) [4] => array ( [@attributes] => array ( [id] => p5 ) [address] => jackson, mi, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => mi [subadministrativearea] => array ( [subadministrativeareaname] => jackson [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 42.2708699 [south] => 42.2036839 [east] => -84.3568169 [west] => -84.4345460 ) ) ) [point] => array ( [coordinates] => -84.4013462,42.2458690,0 ) ) [5] => array ( [@attributes] => array ( [id] => p6 ) [address] => jackson, wi, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => wi [subadministrativearea] => array ( [subadministrativeareaname] => washington [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 43.3387369 [south] => 43.3090429 [east] => -88.1422039 [west] => -88.1917450 ) ) ) [point] => array ( [coordinates] => -88.1667599,43.3238919,0 ) ) [6] => array ( [@attributes] => array ( [id] => p7 ) [address] => jackson, ca, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => ca [subadministrativearea] => array ( [subadministrativeareaname] => amador [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 38.3721550 [south] => 38.3302920 [east] => -120.7489930 [west] => -120.7981980 ) ) ) [point] => array ( [coordinates] => -120.7741018,38.3488023,0 ) ) [7] => array ( [@attributes] => array ( [id] => p8 ) [address] => jackson, ga, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => ga [subadministrativearea] => array ( [subadministrativeareaname] => butts [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 33.3114890 [south] => 33.2638330 [east] => -83.9354860 [west] => -84.0105969 ) ) ) [point] => array ( [coordinates] => -83.9660209,33.2945651,0 ) ) [8] => array ( [@attributes] => array ( [id] => p9 ) [address] => jackson, oh 45640, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => oh [subadministrativearea] => array ( [subadministrativeareaname] => jackson [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 39.0669040 [south] => 39.0062730 [east] => -82.5949490 [west] => -82.7069350 ) ) ) [point] => array ( [coordinates] => -82.6365536,39.0520169,0 ) ) [9] => array ( [@attributes] => array ( [id] => p10 ) [address] => jackson, mo, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 4 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => mo [subadministrativearea] => array ( [subadministrativeareaname] => cape girardeau [locality] => array ( [localityname] => jackson ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 37.4139659 [south] => 37.3385089 [east] => -89.5972280 [west] => -89.7035499 ) ) ) [point] => array ( [coordinates] => -89.6662063,37.3822732,0 ) ) ) )
//data single result starts here
array ( [response] => array ( [name] => 10121 [status] => array ( [code] => 200 [request] => geocode ) [placemark] => array ( [@attributes] => array ( [id] => p1 ) [address] => manhattan, ny 10121, usa [addressdetails] => array ( [@attributes] => array ( [accuracy] => 5 ) [country] => array ( [countrynamecode] => [countryname] => usa [administrativearea] => array ( [administrativeareaname] => ny [dependentlocality] => array ( [dependentlocalityname] => manhattan [postalcode] => array ( [postalcodenumber] => 10121 ) ) ) ) ) [extendeddata] => array ( [latlonbox] => array ( [@attributes] => array ( [north] => 40.7528519 [south] => 40.7489381 [east] => -73.9917906 [west] => -73.9947563 ) ) ) [point] => array ( [coordinates] => -73.9917906,40.7492821,0 ) ) ) )
//data single result ends here
i tried next code desired results no success
foreach ($array $xm) { foreach ($xm $points=>$pointkey) { foreach($pointkey $cor=>$corkey) { echo $cor["coordinates"]; } } }
it gives me warning "warning: invalid argument supplied foreach() in foreach($pointkey $cor=>$corkey)"
try like:
$coords = array(); foreach ($data['placemark'] $entry) { // $data holds finish array $coords[] = $entry['point']['coordinates']; } var_dump($coords);
for 1 result can access coordinates directly, like:
var_dump($data['response']['placemark']['point']['coordinates']);
php multidimensional-array
Comments
Post a Comment