#47642 [Opn]: array_unique() does not work with multidimensional arrays
| From: | iliaa@php.net | Date: | Sun, 15 Mar 2009 14:38:36 +0000 |
| Subject: | #47642 [Opn]: array_unique() does not work with multidimensional arrays | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1984@lists.php.net to get a copy of this message | ||
ID: 47642
Updated by: iliaa@php.net
Reported By: djungowski at chip dot de
Status: Open
-Bug Type: Arrays related
+Bug Type: Documentation problem
Operating System: *
PHP Version: 5.2.9
New Comment:
The array_unique() was never intended to work with multi-dimensional
arrays.
Previous Comments:
------------------------------------------------------------------------
[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