相交数目不详的PHP数组 [英] Intersect unknown number of arrays in PHP

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

问题描述

我想相交PHP数组的任意数,计数这取决于用户提供的参数,每个都可以有任意数量的元素。

I'm trying to intersect an arbitrary number of PHP arrays, the count of which depends on a user provided parameter, each of which can have any number of elements.

例如:
ARRAY1(1,2,3,4,5)
数组2(2,4,6,8,9,23)
ARRAY3(A,B,3,C,F)
...
arrayN(X1,X2,X3,X4,X5 ...... xn)映射

For example: array1(1, 2, 3, 4, 5) array2(2, 4, 6, 8, 9, 23) array3(a, b, 3, c, f) ... arrayN(x1, x2, x3, x4, x5 ... xn)

由于array_intersect需要PARAMS的名单,我不能建立一个阵列阵列相交,并有工作我身边这样的。我想这个解决方案:<一href=\"http://bytes.com/topic/php/answers/13004-array_intersect-unknown-number-arrays\">http://bytes.com/topic/php/answers/13004-array_intersect-unknown-number-arrays但这并没有工作,因为一个错误报道,array_intersect需要2个或更多PARAMS。

Since array_intersect takes a list of params, I can't build one array of arrays to intersect and have to work my way around this. I tried this solution: http://bytes.com/topic/php/answers/13004-array_intersect-unknown-number-arrays but this did not work, as an error is reported that array_intersect requires 2 or more params.

没有人有任何想法如何处理这个的方式尽可能简单?

Does anyone have any idea how to approach this in a manner as simple as possible?

推荐答案

创建一个新的空数组,添加每个阵列的,那么使用的 call_user_func_array()

Create a new empty array, add each of your arrays to that, then use call_user_func_array()

$wrkArray = array( $userArray1,
                   $userArray2,
                   $userArray3
                 );
$result = call_user_func_array('array_intersect',$wrkArray);

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

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