Page 1 of 1

array_unique

Posted: Sat Feb 16, 2008 3:33 pm
by GeXus
I have the following array...

Code: Select all

 
Array
(
    [0] => Array
        (
            [id] => 2
            [name] => New
        )
 
    [1] => Array
        (
            [id] => 1
            [name] => Old
        )
 
    [2] => Array
        (
            [id] => 2
            [name] => New
        )
 
)
 
When I do array_unique, it returns

Code: Select all

 
Array 
( 
    [0] => Array 
            ( 
                [id] => 2 
                [name] => New 
             ) 
)
 
Shouldn't it include the 'Old' array also?

Re: array_unique

Posted: Sat Feb 16, 2008 4:02 pm
by Christopher
I think that perhaps array_unique() only works on an array of scalars, not an array of arrays.

Re: array_unique

Posted: Sat Feb 16, 2008 4:33 pm
by s.dot
array_unique() will not work recursively through the array. If you read the manual page on array_unique() there are some comments that include recursive functions that may be of interest to you.