在PHP中的数组联盟 [英] Union of arrays in PHP

查看:119
本文介绍了在PHP中的数组联盟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在数学与台3的操作:交,差和工会(统一)。在PHP中,我们可以做到这一点的操作与数组:

We have 3 operations with sets in mathematics: intersection, difference and union (unification). In PHP we can do this operations with arrays:

交集:array_intersect(...)
区别:和array_diff(...)

intersection: array_intersect(...) difference: array_diff(...)

和什么功能是工会吗?没有重复必须在结果阵列(如array_intersect(...)+和array_diff(...))。

and what function is for union? No duplicates must be in result array (like array_intersect(...) + array_diff(...)).

如果在数字指标则array_merge将不会覆盖原来的值,但将附加( PHP文档)。我必须使用哪种功能?

If indexes in numeric then array_merge will not overwrite the original value, but will be appended (PHP docs). What function I must use?

推荐答案

尝试 array_merge

array_unique(array_merge($array1, $array2));

PHP手册

这篇关于在PHP中的数组联盟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆