在PHP多个阵列寻找共同的价值观 [英] Find common values in multiple arrays with PHP

查看:122
本文介绍了在PHP多个阵列寻找共同的价值观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要多个阵列找到共同的价值观。阵列的数目可以是无限的。
示例(从输出的print_r

I need to find common values in multiple arrays. Number of arrays may be infinite. Example (output from print_r)

Array1
(
    [0] => 118
    [1] => 802
    [2] => 800
)
Array2
(
    [0] => 765
    [1] => 801
)
Array3
(
    [0] => 765 
    [1] => 794
    [2] => 793
    [3] => 792
    [4] => 791
    [5] => 799
    [6] => 801
    [7] => 802
    [8] => 800
)

现在,我需要找到那些对他们的所有3个(或以上如果可用)......我该怎么做呢?

now, I need to find the values that are common on all 3 (or more if available) of them.... how do I do that?

感谢名单

推荐答案

<一个href=\"http://www.php.net/manual/en/function.array-intersect.php\"><$c$c>array_intersect()

$intersect = array_intersect($array1,$array2,$array3);

如果你不知道你有多少个数组有,然后建立数组和用户<一个数组href=\"http://www.php.net/manual/en/function.call-user-func-array.php\"><$c$c>call_user_func_array()

If you don't know how many arrays you have, then build up an array of arrays and user call_user_func_array()

$list = array();
$list[] = $array1;
$list[] = $array2;
$list[] = $array3;
$intersect = call_user_func_array('array_intersect',$list);

这篇关于在PHP多个阵列寻找共同的价值观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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