|  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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: tlieske at thl-consulting dot com
New email:
PHP Version: OS:


 [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: Fri Sep 24 01:03:38 2021 UTC