Re: array_intersect question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 2, 2008 at 11:06 PM, Andrej Kastrin <andrej.kastrin@xxxxxxxxx>wrote:

> It works like a charm.
>
> Thanks, Andrej
>
> Tim | iHostNZ wrote:
>
>> I know there must be a more elegant way with array_reduce or something,
>> but
>> I would simply write a function called
>>
>> function array_intersect_m($m_array) {
>>  $intersection = $m_array[0];
>>  for ($i=1; $i < count($m_array); $i++) {
>>    $intersection = array_intersect($m_array[$i], $intersection);
>>  }
>>  return $intersection;
>> }
>>
>> and put that into my library. O and while i'm at it, the array_reduce way
>> would prob be:
>> $m_array =
>> array(array("green","red","blue"),array("green","yellow","red"),array("green","red","purple"),array("green","red","yellow"));
>> array_reduce($m_array, 'array_intersect');
>>
>
I tried this now with array_reduce and it didn't work as i expected. Can
anyone tell me why?
It says argument #1 to array_intersect is not an array, although i have an
array of arrays. Also tried providing $arrayOfArrays[0] as the third
parameter to array_reduce which had the same error.

Thanks,
Tim

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux