Created
April 2, 2018 18:03
-
-
Save phpfiddle/af15ede7d8e6c25a9a06e1458ba06e60 to your computer and use it in GitHub Desktop.
[ Posted by Michaeljpitz ] Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').
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 | |
$str = "abcde"; | |
$a=str_split($str,2); | |
$nb = count($a); | |
if(strlen($a[$nb-1])<2) $a[$nb-1].="_"; | |
var_dump($a); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from codewars.com