Skip to content

Instantly share code, notes, and snippets.

@sedera-tax
Created January 15, 2021 13:40
Show Gist options
  • Save sedera-tax/c98f08a785a40845e8e61120c36611c3 to your computer and use it in GitHub Desktop.
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', '…
<?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
@Barackhalogen
Copy link

This is so efficient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment