As for array_intersect to enumerate many arrays?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
Hello. I'll try to describe the problem I faced and I am suffering for a while. Please help who can.
I need a lot of time to compare several arrays. The number of arrays is different each time (from 2 to 15). Not very convenient every time when you call the function array_intersect in parentheses to specify the number of arrays manually. The names of the arrays have this form:
"$names[0], $names[1], $names[2], $names[3], $names[4]..."
Using code I can machine to make a list of these arrays. Type:
$all_arrays = '$names[0], $names[1], $names[2], $names[3], $names[4], $names[5]';
But how to register in brackets after the function array_intersect ? If you insert them like this:
$intersect = array_intersect($all_arrays) - gives an error.
I understand why it gives an error, but how to do it properly? How to specify in parentheses the functions of the different number of arrays? I have tried using echo (I know that it's stupid, but I tried). Tried differently: using a loop to compare two arrays in a single cycle, but there was a problem.
I don't know much about PHP programming, but really need to solve this problem.
Sorry for the stupidity if that. Thanks in advance for your help.
by | 15 views

3 Answers

0 like 0 dislike
0 like 0 dislike

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


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

ie in your case
$result = call_user_func_array('array_intersect', $names);
0 like 0 dislike

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
40,796 users