Last active
July 3, 2017 21:56
-
-
Save wilcorrea/82428509c25f88cf166b026042158f2e to your computer and use it in GitHub Desktop.
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 | |
/** | |
* @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 ($item) { | |
return ((string)$item){0}; | |
}; | |
return implode('', array_map($function, $input)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment