note 118680 added to function.array-unique
| From: | zoolyka at gmail dot com | Date: | Mon, 18 Jan 2016 22:48:15 +0000 |
| Subject: | note 118680 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204713@lists.php.net to get a copy of this message | ||
I found the simplest way to "unique" multidimensional arrays as follows:
<?php
$array = array(
'a' => array(1, 2),
'b' => array(1, 2),
'c' => array(2, 2),
'd' => array(2, 1),
'e' => array(1, 1),
);
$array = array_map('json_encode', $array);
$array = array_unique($array);
$array = array_map('json_decode', $array);
print_r($array);
?>
As you can see "b" will be removed without any errors or notices.
----
Server IP: 72.52.91.14
Probable Submitter: 89.132.250.40
----
Manual Page -- http://php.net/manual/en/function.array-unique.php
Edit -- https://master.php.net/note/edit/118680
Del: integrated -- https://master.php.net/note/delete/118680/integrated
Del: useless -- https://master.php.net/note/delete/118680/useless
Del: bad code -- https://master.php.net/note/delete/118680/bad+code
Del: spam -- https://master.php.net/note/delete/118680/spam
Del: non-english -- https://master.php.net/note/delete/118680/non-english
Del: in docs -- https://master.php.net/note/delete/118680/in+docs
Del: other reasons-- https://master.php.net/note/delete/118680
Reject -- https://master.php.net/note/reject/118680
Search -- https://master.php.net/manage/user-notes.php