如何在php中连接两个数组?

How to concatenate two arrays in php?

我有两个由两个SQL查询生成的数组,分别是$array_1和$array_2。两者都包含[0]个索引。我想将它们与索引[0]、[1]等连接起来…所以有谁能帮我在PHP中连接两个数组吗?


数组合并-合并一个或多个数组

说明

1
array array_merge ( array $array1 [, array $... ] )

Merges the elements of one or more arrays together so that the values
of one are appended to the end of the previous one. It returns the
resulting array.

If the input arrays have the same string keys, then the later value
for that key will overwrite the previous one. If, however, the arrays
contain numeric keys, the later value will not overwrite the original
value, but will be appended.

Values in the input array with numeric keys will be renumbered with
incrementing keys starting from zero in the result array.

压缩数组:

如果希望[0]array1[0][1]array2[0]等,可以对数组进行压缩;

有没有像python的zip这样的PHP函数?


我猜你在找array_merge

https://www.w3schools.com/php/func_array_merge.asp

在您的案例中:array_merge($array_1,$array_2)