Created
September 18, 2017 06:25
-
-
Save HoangPV/a95e50af943e36029492becc73209a90 to your computer and use it in GitHub Desktop.
Replace With Alphabet Position (alt solution)
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 | |
function alphabet_position( $str ) { | |
$str = strtolower( $str ); | |
$alphabetChars = 'abcdefghijklmnoqrstuvwxyz'; | |
$report=[]; | |
foreach (str_split($str) as $char) { | |
$g = (strpos($alphabetChars, $char) !== false) ? strpos($alphabetChars, $char) : ''; | |
if ($g!=='') { | |
$report[] = $g+1; | |
} | |
} | |
return implode(' ', $report); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment