Good, I have a problem with PHP Arrays. I'm doing an address lookup in google maps, and JSON returns me the following array:
Array
(
[results] => Array
(
[0] => Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => Rua Vicente Velasco
[short_name] => R. Vicente Velasco
[types] => Array
(
[0] => route
)
)
[1] => Array
(
[long_name] => Uep5-S.2
[short_name] => Uep5-S.2
[types] => Array
(
[0] => political
[1] => sublocality
[2] => sublocality_level_1
)
)
[2] => Array
(
[long_name] => Presidente Prudente
[short_name] => Pres. Prudente
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[3] => Array
(
[long_name] => São Paulo
[short_name] => SP
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[4] => Array
(
[long_name] => Brazil
[short_name] => BR
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => R. Vicente Velasco - Uep5-S.2, Pres. Prudente - SP, Brazil
[geometry] => Array
(
[bounds] => Array
(
[northeast] => Array
(
[lat] => -22.0730082
[lng] => -51.3799775
)
[southwest] => Array
(
[lat] => -22.0748567
[lng] => -51.3807562
)
)
[location] => Array
(
[lat] => -22.0737691
[lng] => -51.3804065
)
[location_type] => GEOMETRIC_CENTER
[viewport] => Array
(
[northeast] => Array
(
[lat] => -22.072583469709
[lng] => -51.379017869709
)
[southwest] => Array
(
[lat] => -22.075281430292
[lng] => -51.381715830291
)
)
)
[partial_match] => 1
[place_id] => ChIJY3XgbV32k5QRQmh9Ne1joeo
[types] => Array
(
[0] => route
)
)
)
[status] => OK
)
However, some addresses are not returning the zip code, due to some failure to register with Google itself. With this in my project check if the CEP came missing and if so I do a second search in the WebService viacep.com.br, and from there I get the zip code, however I need to reassemble this array that came from google by joining the field of zip code that came of ViaCEP to return in my main function. Knowing that the zip position in Google's Array when the address comes complete is:
['results'][0]['address_components'][6]['long_name']
I can set up an array with the same pattern as Google with only the zip code (given this returned from ViaCep's WebService), with the value in position 6 and its sub-keys due:
Array
(
[results] => Array
(
[0] => Array
(
[address_components] => Array
(
[1] => Array
(
[] =>
)
[2] => Array
(
[] =>
)
[3] => Array
(
[] =>
)
[4] => Array
(
[] =>
)
[5] => Array
(
[] =>
)
[6] => Array
(
[long_name] => 19036-068
[types] => Array
(
[0] => postal_code
)
)
)
)
)
)
I looked at the PHP documentation but could not apply anything (in a practical way) to make this union! I tried using array_merge_recursive (); But it creates the second array as a different index! = /
I would like an exit joining this two as if the data had left one place!
Does anyone have any suggestions?
Thank you!