note 103963 deleted from function.array-unique by danbrown

From: Date: Sat, 14 May 2011 01:40:48 +0000
Subject: note 103963 deleted from function.array-unique by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179711@lists.php.net to get a copy of this message
Note Submitter: iim dot vxk at gmail dot com ---- // an easiest way to get unique AND duplicated items... $unique=array("","A1","","A2","","A1",""); $duplicated=array(); foreach($unique as $k=>$v) { while( ($kt=array_search($v,$unique))!==false and $k!=$kt ) { unset($unique[$kt]); $duplicated[]=$v; } } var_export($unique); var_export($duplicated); // will output array ( 3 => 'A2', 5 => 'A1', 6 => '', ) array ( 0 => '', 1 => '', 2 => 'A1', 3 => '', )

« previous php.notes (#179711) next »