Voting

: max(eight, four)?
(Example: nine)

The Note You're Voting On

Ray dot Paseur at SometimesUsesGmail dot com
17 years ago
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] = '[email protected]';
$raw_array[2] = '[email protected]';
$raw_array[3] = '[email protected]';
$raw_array[4] = '[email protected]'; // Duplicate

$common_stuff = array_not_unique($raw_array);
var_dump($common_stuff);
?>

<< Back to user notes page

To Top