公司阵列
array(1) {
[0]=> array(19) {
["entityid"]=> string(4) "3626"
["entityparentid"]=> string(1) "0"
["entityduplicateof"]=> string(1) "0"
["entitytype"]=> string(1) "0"
["entityname"]=> string(12) "Facebook Inc"
}
}
Run Code Online (Sandbox Code Playgroud)
距离阵列
array(1) {
["distance"]=> string(4) "1.22"
}
Run Code Online (Sandbox Code Playgroud)
我希望输出看起来像:
array(1) {
[0]=> array(19) {
["entityid"]=> string(4) "3626"
["entityparentid"]=> string(1) "0"
["entityduplicateof"]=> string(1) "0"
["entitytype"]=> string(1) "0"
["entityname"]=> string(12) "Facebook Inc"
["distance"]=> string(4) "1.22" // here
}
}
Run Code Online (Sandbox Code Playgroud)
题:
array_push($company_array,$distance_array); 似乎没有做我想做的事.
它将它添加到最后,但不是我想要的地方(注意它放置的位置不同):
array(1) {
[0]=> array(19) {
["entityid"]=> string(4) "3626"
["entityparentid"]=> string(1) "0"
["entityduplicateof"]=> string(1) "0"
["entitytype"]=> string(1) "0"
["entityname"]=> string(12) "Facebook Inc"
},
["distance"]=> string(4) "1.22" // not here
}
Run Code Online (Sandbox Code Playgroud)
它内部有另一个级别$company,如果您想要另一个嵌套内部的单个数组,请将其直接指向索引零,然后使用array_merge:
$company[0] = array_merge($company[0], $distance);
Run Code Online (Sandbox Code Playgroud)