I have a response in below format. I am using laravel.
I want to check if there is street_number present or not despite of their index and if yes just print the long_name
similar I want to check if there is route in types of this array or not. if yes print route long_name and so on.
dd($dataArray); gives this response
array:3 [
"html_attributions" => []
"result" => array:15 [
"address_components" => array:7 [
0 => array:3 [
"long_name" => "19"
"short_name" => "19"
"types" => array:1 [
0 => "street_number"
]
]
1 => array:3 [
"long_name" => "Becket Street South"
"short_name" => "Becket St S"
"types" => array:1 [
0 => "route"
]
]
2 => array:3 [
"long_name" => "senroy"
"short_name" => "Slenroy"
"types" => array:2 [
0 => "locality"
1 => "political"
]
]
]
I am looping like this
$newArray=[];
foreach($dataArray['result'] as $data){
// check if street_number in array or not if yes push it value to new array
//same for other types as well
}
typesviain_arrayso that you don't need to use a hardcoded index, it'll just check ifstreet_addressexists