json необходимо вывести определенные данные
Есть json, как из него получить определенные данные,например мне необходимо вывести только (id,adress,city,workingHours,coordinates)
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 0,
"geometry": {
"type": "Point",
"coordinates": [
"54.101023",
"37.580223"
]
},
"properties": {
"id": 0,
"address": "ул. Грибоедова, д. 54",
"terminal": true,
"alcohol": true,
"iconContent": 12,
"city": "2-й Западный",
"workingHours": "09:00-23:00"
},
"options": {
"iconLayout": "default#image",
"iconImageHref": "/map_img/placemark.png",
"iconImageSize": [
"32",
"50"
],
"iconImageOffset": [
"-16",
"-50"
],
"iconShape": {
"type": "Rectangle",
"coordinates": [
[
-16,
-50
],
[
16,
0
]
]
}
}
}
Ответы (1 шт):
Автор решения: Hopex Development
→ Ссылка
$content = '{"type":"FeatureCollection","features":[{"type":"Feature","id":0,"geometry":{"type":"Point","coordinates":["54.101023","37.580223"]},"properties":{"id":0,"address":"ул. Грибоедова, д. 54","terminal":true,"alcohol":true,"iconContent":12,"city":"2-й Западный","workingHours":"09:00-23:00"},"options":{"iconLayout":"default#image","iconImageHref":"/map_img/placemark.png","iconImageSize":["32","50"],"iconImageOffset":["-16","-50"],"iconShape":{"type":"Rectangle","coordinates":[[-16,-50],[16,0]]}}}]}';
$data = json_decode($content);
$out = [
'id' => $data->features[0]->id,
'address' => $data->features[0]->properties->address,
'city' => $data->features[0]->properties->city,
'workingHours' => $data->features[0]->properties->workingHours,
'coordinates' => $data->features[0]->geometry->coordinates,
];
echo '<pre>';
var_export($out);
echo '</pre>';
На выходе все что вам нужно:
array (
'id' => 0,
'adress' => 'ул. Грибоедова, д. 54',
'city' => '2-й Западный',
'workingHours' => '09:00-23:00',
'coordinates' =>
array (
0 => '54.101023',
1 => '37.580223',
),
)