我有两个阵列。
第一个阵列:
Array
(
[0] => Array
(
[0] => 17, karol Bagh
[1] => Noida
[2] => Delhi
[3] => India
[4] => 426001
)
[1] => Array
(
[0] => 117, Srinagar
[1] => Gaziabad
[2] => Delhi
[3] => India
[4] => 426001
)
[2] => Array
(
[0] => 109,Bangalore
[1] => Bangalore
[2] => Karnataka
[3] => India
[4] => 560058
)
[3] => Array
(
[0] => Jeevan Shree Building, Ground Floor,S.No.1109, Ganeshkhind Road, Shivajinagar, Near Pune Central
[1] => Pune
[2] => Maharashtra
[3] => India
[4] => 411005
)
)
第二阵列:
Array
(
[0] => Array
(
[LatitudeLongitude] => 28.6192015, 77.2791726
)
[1] => Array
(
[LatitudeLongitude] => 28.5615316, 77.268723
)
[2] => Array
(
[LatitudeLongitude] => 13.0525001, 77.4869828
)
[3] => Array
(
[LatitudeLongitude] => 18.5204303, 73.8567437
)
)
我需要一个数组,比如在php中组合这两个数组:
Array
(
[0] => Array
(
[0] => 17, karol Bagh
[1] => Noida
[2] => Delhi
[3] => India
[4] => 426001
**[5] => 28.6192015, 77.2791726**
)
[1] => Array
(
[0] => 117, Srinagar
[1] => Gaziabad
[2] => Delhi
[3] => India
[4] => 426001
**[5] => 28.5615316, 77.268723**
)
[2] => Array
(
[0] => 109,Bangalore
[1] => Bangalore
[2] => Karnataka
[3] => India
[4] => 560058
**[5] => 13.0525001, 77.4869828**
)
[3] => Array
(
[0] => Jeevan Shree Building, Ground Floor,S.No.1109, Ganeshkhind Road, Shivajinagar, Near Pune Central
[1] => Pune
[2] => Maharashtra
[3] => India
[4] => 411005
**[5] => 18.5204303, 73.8567437**
)
)
怎么做?
答案 0 :(得分:-1)
您可以执行以下操作:
foreach ($array1 as $key => $a) {
$array1[$key][] = $array2[$key]['LatitudeLongitude'];
}
这样,您将迭代整个第一个数组,从第二个数组中的右键获取LatittudeLongitude
索引。
希望我有所帮助
答案 1 :(得分:-1)
$index = 0;
foreach ($array2 as $entry) {
array_push($array1[$index], $entry['LatitudeLongitude']);
$index++;
}
此代码段循环遍历第二个数组,您将在其中保存lat / lng数据。我们正在获取第二个数组中每个条目的['LatitudeLongitude']字段,并将其推入存在于第一个数组中相同索引处的嵌套数组中。递增的变量充当我们在两个数组中的位置的引用。
所以我们始终有$2ndarray[0]['LatitudeLongitude'] -> $1starray[0]
,$2ndarray[1]['LatitudeLongitude'] -> $1starray[1]
,....等等(其中$1starray[$i]
是一个数组本身。)