Created
February 20, 2024 13:35
-
-
Save 4RSIM3R/cf6c10007c8af8abebc70c0a0724aff7 to your computer and use it in GitHub Desktop.
Generate Company Alias
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
function shortenName(string $name): string | |
{ | |
$words = explode(' ', $name); | |
$shortened = ''; | |
foreach ($words as $word) { | |
// Take the first letter of each word and concatenate | |
$shortened .= strtoupper(substr($word, 0, 1)); | |
} | |
return $shortened; | |
} | |
echo shortenName("Kereta Api Indonesia"); // KAI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment