note 95203 added to function.array-unique

From: Date: Fri, 18 Dec 2009 10:36:34 +0000
Subject: note 95203 added to function.array-unique
Groups: php.notes 
Request: Send a blank email to php-notes+get-164102@lists.php.net to get a copy of this message
I searched how to show only the duplicate elements from array, but failed. Here is my solution: <?php function arrayDuplicate($array) { return array_unique(array_diff_assoc($array1,array_unique($array1))); }; ?> Example: <?php $arr1 = array('foo', 'bar', 'xyzzy', '&', 'xyzzy', 'baz', 'bat', '|', 'xyzzy', 'plugh', 'xyzzy', 'foobar', '|', 'plonk', 'xyzzy', 'apples', '&', 'xyzzy', 'oranges', 'xyzzy', 'pears','foobar'); $result=arrayDuplicate($arr1); print_r($result);exit; ?> Output: <?php Array ( [4] => xyzzy [12] => | [16] => & [21] => foobar ) See the link for more info (Bulgarian php blog): 'http://www.mpetrov.net' ---- Server IP: 69.147.83.197 Probable Submitter: 83.228.93.76 ---- Manual Page -- http://www.php.net/manual/en/function.array-unique.php Edit -- https://master.php.net/note/edit/95203 Del: integrated -- https://master.php.net/note/delete/95203/integrated Del: useless -- https://master.php.net/note/delete/95203/useless Del: bad code -- https://master.php.net/note/delete/95203/bad+code Del: spam -- https://master.php.net/note/delete/95203/spam Del: non-english -- https://master.php.net/note/delete/95203/non-english Del: in docs -- https://master.php.net/note/delete/95203/in+docs Del: other reasons-- https://master.php.net/note/delete/95203 Reject -- https://master.php.net/note/reject/95203 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164102) next »