|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16715 array_unique results in only one entry in the array
Submitted: 2002-04-20 14:53 UTC Modified: 2002-06-22 08:26 UTC
From: tlieske at thl-consulting dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.1.2 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
22 + 1 = ?
Subscribe to this entry?

 [2002-04-20 14:53 UTC] tlieske at thl-consulting dot com
The following code should demonstrate that unusual behavior (becaue I'm still not convinced that this is a bug)

$input = array ( array (1,1), array (1,2), array(1,2), array(1,1) );
$result = array_unique ($input);

The result is :
    [0] => Array
            [0] => 1
            [1] => 1

This was not what I was expecting. I was expecting the following result :
    [0] => Array
            [0] => 1
            [1] => 1

    [1] => Array
            [0] => 1
            [1] => 2


This is the result You get if You use PHP Version 4.0.4pl1 and before for example.
So it is up to You, if You call this a bug or if I just have missused the function array_unique because I was not using a one dimensional array.
Hopefully that helps You and me.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-22 08:26 UTC]
array_unique() doesn't work with array of arrays since all
entries are compared as strings. As a string an array is
represented as just "Array". Try say echo array(1,2);
See comments in manual for possible work-around. If the
string representation was say serialize(...) ...

You are right that it worked before, but not comparing all entries as strings had some serious side-effects. If you or others want it to support arrays, you could try to implement it or file a feature request.
Since this is not a bug, in my opinion, I'm classifying it
as bogus, although you are correct in your description.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 23 06:03:33 2021 UTC