array_unique

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

array_unique

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: array_unique

Post by Christopher »

I think that perhaps array_unique() only works on an array of scalars, not an array of arrays.
(#10850)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: array_unique

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply