Page 1 of 1

Help with arrays

Posted: Thu May 13, 2010 6:43 pm
by rfeio
Hi!

I have this script that generates a multiple array: array[x][y] Depending on the user input the array can be 'x' can be 1 or more.

I want to use the array[x] with the array_intersect as in array_intersect($array[0], $array[1], ...) So I thought of doing:
for($k=0; $k < count($array); $k++)
{
$temp .= '$array['.$k.'],';
} and then issuing:
array_intersect($temp) but obviously it doesn't work.

So my question is, how can I do this?

Cheers!

Re: Help with arrays

Posted: Thu May 13, 2010 8:08 pm
by Christopher
You say that you "want to use the array[x] with the array_intersect", but you don't say what you want to do with the arrays? Can you show what the resulting array should look like?

Re: Help with arrays

Posted: Fri May 14, 2010 6:03 am
by rfeio
Well, the idea is to check the values that are common to all the arrays.

For example let's suppose that:

array[1] has the values (a, b, c, d, e)

array[2] has the values (a, e, f, g, h)

array[3] has the values (e, f, g, h, k)

The end result should be 'e' which is common to all the 3 arrays.

Now one of the challenges is that I don't know how many arrays I will have in the beginning. In this example it was 3, but it can be more or less then that.

Any ideas?

Re: Help with arrays

Posted: Fri May 14, 2010 7:18 am
by rfeio
Ok, merging the arrays in one single array with array_merge() and then filtering the results with array_unique() solved my problem.