Q:

Write a PHP program to identify the email addresses which are not unique

0

Write a PHP program to identify the email addresses which are not unique

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function array_not_unique($my_array) {
    $same = array();
    natcasesort($my_array);
    reset ($my_array);

    $old_key    = NULL;
    $old_value    = NULL;
    foreach ($my_array as $key => $value) {
        if ($value === NULL) { continue; }
        if ($old_value == $value) {
            $same[$old_key]    = $old_value;
            $same[$key]        = $value;
        }
        $old_value    = $value;
        $old_key    = $key;
    }
return $same;
}

$test_array = array();
$test_array[1]    = 'xyz@example.com';
$test_array[2]    = 'dse@example.com';
$test_array[3]    = 'xyz@example.com';
$test_array[4]    = 'mno@example.com';

print_r(array_not_unique($test_array));
?>

Sample Output:

Array                                                               
(                                                                   
    [1] => xyz@example.com                                          
    [3] => xyz@example.com                                          
)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now