Re: array_intersect question
| From: | German Geek | Date: | Thu, 11 Dec 2008 03:30:10 +0000 |
| Subject: | Re: array_intersect question | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-284458@lists.php.net to get a copy of this message | ||
On Tue, Dec 2, 2008 at 11:06 PM, Andrej Kastrin <andrej.kastrin@gmail.com>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