php.net |  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
 [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);
print_r($result);

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

This was not what I was expecting. I was expecting the following result :
Array
(
    [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.

Cheers
Thomas

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-22 08:26 UTC] venaas@php.net
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-2019 The PHP Group
All rights reserved.
Last updated: Mon Dec 16 05:01:25 2019 UTC