note 98554 deleted from function.array-intersect by danbrown

From: Date: Fri, 25 Jun 2010 15:19:57 +0000
Subject: note 98554 deleted from function.array-intersect by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170450@lists.php.net to get a copy of this message
Note Submitter: sg dot ping at hotmail dot com ---- Here's yet another way to fetch duplicate entries. The previously submitted function by Barış was only capable of fetching values that occurred only twice. This one, however, can fetch duplicates that occur twice and more. Give it a shot ;) <?php function get_duplicates($array1, $array2){ // store both arrays in one array foreach($array1 as $value1){ $dup_values[] = $value1; } foreach($array2 as $value2){ $dup_values[] = $value2; } sort($dup_values); foreach($dup_values as $value){ // counter++ if current and previous values are the same if($value == $prev){ $counter++; } // if the value occurs more than once and the current value is different from the previous if(($counter >= 1) && ($value != $prev)){ // so store the 'previous' value to the final array $tblFinal[] = $prev; // and reset counter since it's not used anymore $counter = 0; } // store value in a string for comparison $prev = $value; } return $tblFinal; } ?> Simon G.

« previous php.notes (#170450) next »