Created
January 15, 2021 13:40
-
-
Save sedera-tax/c98f08a785a40845e8e61120c36611c3 to your computer and use it in GitHub Desktop.
2. Merge Names Implement the unique_names function. When passed two arrays of names, it will return an array containing the names that appear in either or both arrays. The returned array should have no duplicates. For example, calling unique_names(['Ava', 'Emma', 'Olivia'], ['Olivia', 'Sophia', 'Emma']) should return ['Emma', 'Olivia', 'Ava', '…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function unique_names(array $array1, array $array2) : array | |
{ | |
return array_unique(array_merge($array1, $array2)); | |
} | |
$names = unique_names(['Ava', 'Emma', 'Olivia'], ['Olivia', 'Sophia', 'Emma']); | |
echo join(', ', $names); // should print Emma, Olivia, Ava, Sophia |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is so efficient