hello,
I have 4 arrays... i need to intersect their elements (array_intersect).
The problem is that i need to check every array to see if is empty(no elements). If there is one(or two/or three/or all the four->message)empty, then the array must be cut off from array_intersect function...
thx !!!
Array Help Pls
i don't know how 2 write the algorithm....with 16 if ????
-if count() of all arrays are >0
array_intersect(array1, array2,array3, array4)
-if count(array1) is ==0 then
array_intersect(array2,array3, array4)
-if count(array2) and count(array4) ==0 then
array_intersect(array1,array3)
.....and so on ....
Two things that would reduce that code down to something that looks more intelligent: [man]references[/man] and the [man]call_user_func_array/man function. For example, you could build an array of references to non-empty arrays like so:
$arrays = array(&$array1, &$array2, &$array3, &$array4);
$arrays = array_filter($arrays);
Now you simply call [man]call_user_func_array/man to invoke the 'array_intersection' filter on the non-empty arrays.
i'll try...thank you very much