-
-
Save marcelod/e5dad925278d0fbde91032e8d893bb12 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* @param string $string | |
* @param array $avoid (['de', 'da', 'a', 'e', 'o']) | |
* @return string | |
*/ | |
function initials(string $string, array $avoid = null): string | |
{ | |
$words = preg_split("/\s+/", $string); | |
$restrict = $avoid ? $avoid : ['de', 'da', 'a', 'e', 'o']; | |
$input = array_diff($words, $restrict); | |
$function = function ($carry, $item) { | |
$carry[] = ((string)$item){0}; | |
return $carry; | |
}; | |
return implode('', array_reduce($input, $function, [])) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment