#47642 [Opn->Csd]: array_unique() does not work with multidimensional arrays

From: Date: Thu, 26 Mar 2009 01:34:15 +0000
Subject: #47642 [Opn->Csd]: array_unique() does not work with multidimensional arrays
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2044@lists.php.net to get a copy of this message
 ID:               47642
 Updated by:       kalle@php.net
 Reported By:      djungowski at chip dot de
-Status:           Open
+Status:           Closed
 Bug Type:         Documentation problem
 Operating System: *
 PHP Version:      5.2.9
-Assigned To:      
+Assigned To:      kalle
 New Comment:

This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.




Previous Comments:
------------------------------------------------------------------------

[2009-03-15 14:38:35] iliaa@php.net

The array_unique() was never intended to work with multi-dimensional 
arrays.

------------------------------------------------------------------------

[2009-03-13 10:56:00] djungowski at chip dot de

Description:
------------
array_unique does not work, when it comes to multidimensional arrays.
I've posted the behaviour + a workaround here:
http://www.phpdevblog.net/2009/01/using-array-unique-with-multidimensional-arrays.html#comment505

I've also found the (older) bug report #12789, where Jeroen says that
array_unique is not supposed to work with multidimensional arrays.

If this is so, you should at least mention it in the documentation (see
the older bug report! James says the same thing)

Reproduce code:
---------------
$array = array(
    array(
        'id'    => 123,
        'name'  => 'Some Product',
        'ean'   => '1234567890123'
    ),
    array(
        'id'    => 123,
        'name'  => 'Some Product',
        'ean'   => '4852950174938'
    ),
    array(
        'id'    => 123,
        'name'  => 'Some Product',
        'ean'   => '1234567890123'
    ),
);
$uniqueArray = array_unique($array);
var_dump($uniqueArray);

Expected result:
----------------
array(2) {
  [0]=>
  array(3) {
    ["id"]=>
    int(123)
    ["name"]=>
    string(12) "Some Product"
    ["ean"]=>
    string(13) "1234567890123"
  }
  [1]=>
  array(3) {
    ["id"]=>
    int(123)
    ["name"]=>
    string(12) "Some Product"
    ["ean"]=>
    string(13) "4852950174938"
  }
}

Actual result:
--------------
array(1) {
  [0]=>
  array(3) {
    ["id"]=>
    int(123)
    ["name"]=>
    string(12) "Some Product"
    ["ean"]=>
    string(13) "1234567890123"
  }
}


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47642&edit=1



Thread (2 messages)

« previous php.doc.bugs (#2044) next »