合并两个数组

24 浏览
0 Comments

合并两个数组

这个问题已经有了答案

PHP - 合并两个数组成一个数组(同时删除重复项)

我有两个数组,其中一个是另一个的超集,如何创建第三个数组,该数组具有两个数组的所有值,但不重复?

请帮助我。

$a = array(1,2,3);
$b = array(1,2,3,4);

输出必须像这样。

$c = array(1,2,3,4);

admin 更改状态以发布 2023年5月23日
0
0 Comments

$c = array_unique(array_merge($a, $b));

所有这些内容都可以在此链接中查看:https://php.net/manual/en/function.array-merge.php

0
0 Comments

使用array_merge()array_unique()

array_unique(array_merge($a,$b));

输出结果: - https://3v4l.org/lfm1b

注意: 如果要重新索引数组,使用array_values() [在我的工作示例链接中添加]

参考:

array_values()

0