Okay, if feel like this should be really simple and accomplished by a function like array_merge()
or array_merge_recursive
, but I can't quite figure it out. I have two simple arrays structured like the (simplified) example below. I simply want to merge 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
)
)
$desiredResult :
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 merge these 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 loop through to push the second set into the first, or can this be done with an existing function?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…