#47642 [Opn->Csd]: array_unique() does not work with multidimensional arrays
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)