OK, I've done some searching on this and tried some code but haven't found anything that seems to help.
It ought to be a simple problem to solve. I guess it's also a common one.
I have an array of IDs - they're Soccer Player IDs to be specific, chosen by a user on a web form. It's possible that they might pick the same player more than once, and I'd like to report this to them as an error.
So, I know I can remove duplicates by using array_unique. And I can then compare the number of items in each array to find out if there were duplicates. But, how can I find out what the duplicate values were?
I guess I can iterate through the unique array, and count how many times each value appears in the original. It seems like a long-winded approach.
Any help would be appreciated, thanks.
function check_for_duplicates ($player_1, $player_2, $player_3, $player_4, $player_5, $player_6, $player_7, $player_8, $player_9, $player_10, $player_11) {
//Put the Player IDs into an array
$chosen_players = array($player_1, $player_2, $player_3, $player_4, $player_5, $player_6, $player_7, $player_8, $player_9, $player_10, $player_11);
//Remove duplicates
$unique_players = array_unique($chosen_players);
//Now check if there are any duplicates
if (count($chosen_players) > count($unique_players)) {
return False;
} else {
return True;
}
}