It’s good if such a feeling should be really simple and executed using a function like array_merge()or array_merge_recursive, but I can’t understand it. I have two simple arrays structured as an example (simplified) below. I just want to combine them into one array based on their index.
$ array 1:
Array (
[0] => Array (
[ID] => 201
[latLng] => 45.5234515, -122.6762071
)
[1] => Array (
[ID] => 199
[latLng] => 37.7931446, -122.39466520000002
)
)
et cetera ...
$ array2:
Array (
[0] => Array (
[distance] => 1000
[time] => 10
)
[1] => Array (
[distance] => 1500
[time] => 15
)
)
$ wishResult:
Array (
[0] => Array (
[ID] => 201
[latLng] => 45.5234515, -122.6762071
[distance] => 1000
[time] => 10
)
[1] => Array (
[ID] => 199
[latLng] => 37.7931446, -122.39466520000002
[distance] => 1500
[time] => 15
)
)
When I try to combine them using merge functions, I can only get this:
$ unDesiredResult:
Array (
[0] => Array (
[ID] => 201
[latLng] => 45.5234515, -122.6762071
)
[1] => Array (
[ID] => 199
[latLng] => 37.7931446, -122.39466520000002
)
[2] => Array (
[distance] => 1000
[time] => 10
)
[3] => Array (
[distance] => 1500
[time] => 15
)
)
Do I need to iterate over to insert the second set into the first, or can this be done using an existing function?
source
share