Skip to content

Instantly share code, notes, and snippets.

@irsyadrdp
Last active January 3, 2019 07:16
Show Gist options
  • Save irsyadrdp/c99d309d78e174fe261a70b48ab3c46a to your computer and use it in GitHub Desktop.
Save irsyadrdp/c99d309d78e174fe261a70b48ab3c46a to your computer and use it in GitHub Desktop.
Merge Names
<?php
class MergeNames
{
public static function unique_names($array1, $array2)
{
// Join array, distinct array (removes duplicate)
return array_unique(array_merge($array1, $array2));
}
}
// Sample test
$names = MergeNames::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