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

标签 php arrays

<分区>

我有两个数组,它们是从两个 sql 查询生成的,分别是 $array_1 和 $array_2。都包含 [0] 个索引。我想用索引 [0]、[1] 等等来加入它们......所以任何人都可以帮助我如何在 php 中连接两个数组

最佳答案

array_merge — Merge one or more arrays

描述

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] 等,你可以压缩数组;

Is there a php function like python's zip?

关于php - 如何在php中连接两个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43318013/

相关文章:

objective-c - 在 Objective-C 中逗号分隔的字符串到 NSArray

php - Yii中的错误处理

javascript - 对 HTML 进行编码并将其从 PHP 传递到 Javascript

php - 这些值未发布到数据库

javascript - 在同一位置输出具有相同值的对象

php - 如何访问数组的对象(stdClass Object)成员/元素的属性?

php - TIMEDIFF GROUP BY 涉及天数

php - Malihu 自定义滚动条 Ajax 内容 .mCSB_container 宽度未更新

arrays - 将数组转换为指标矩阵

java - 数组空指针异常错误