note 81513 added to function.array-unique

From: Date: Sun, 02 Mar 2008 03:46:09 +0000
Subject: note 81513 added to function.array-unique
Groups: php.notes 
Request: Send a blank email to php-notes+get-136652@lists.php.net to get a copy of this message
I needed to identify email addresses in a data table that were replicated, so I wrote the array_not_unique() function: <?php function array_not_unique($raw_array) { $dupes = array(); natcasesort($raw_array); reset ($raw_array); $old_key = NULL; $old_value = NULL; foreach ($raw_array as $key => $value) { if ($value === NULL) { continue; } if ($old_value == $value) { $dupes[$old_key] = $old_value; $dupes[$key] = $value; } $old_value = $value; $old_key = $key; } return $dupes; } $raw_array = array(); $raw_array[1] = 'abc@xyz.com'; $raw_array[2] = 'def@xyz.com'; $raw_array[3] = 'ghi@xyz.com'; $raw_array[4] = 'abc@xyz.com'; // Duplicate $common_stuff = array_not_unique($raw_array); var_dump($common_stuff); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 72.192.214.87 ---- Manual Page -- http://www.php.net/manual/en/function.array-unique.php Edit -- https://master.php.net/note/edit/81513 Del: integrated -- https://master.php.net/note/delete/81513/integrated Del: useless -- https://master.php.net/note/delete/81513/useless Del: bad code -- https://master.php.net/note/delete/81513/bad+code Del: spam -- https://master.php.net/note/delete/81513/spam Del: non-english -- https://master.php.net/note/delete/81513/non-english Del: in docs -- https://master.php.net/note/delete/81513/in+docs Del: other reasons-- https://master.php.net/note/delete/81513 Reject -- https://master.php.net/note/reject/81513 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136652) next »