Write a PHP program to identify the email addresses which are not unique
<?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 )
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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