php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #47642 array_unique() does not work with multidimensional arrays
Submitted: 2009-03-13 10:56 UTC Modified: 2009-03-26 01:34 UTC
From: djungowski at chip dot de Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.9 OS: *
Private report: No CVE-ID: None
 [2009-03-13 10:56 UTC] 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"
  }
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-15 14:38 UTC] iliaa@php.net
The array_unique() was never intended to work with multi-dimensional 
arrays.
 [2009-03-26 01:34 UTC] kalle@php.net
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.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 03 16:00:01 2025 UTC