Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created April 2, 2018 18:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/af15ede7d8e6c25a9a06e1458ba06e60 to your computer and use it in GitHub Desktop.
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 ('_').
<?php
$str = "abcde";
$a=str_split($str,2);
$nb = count($a);
if(strlen($a[$nb-1])<2) $a[$nb-1].="_";
var_dump($a);
?>
@mikhawa
Copy link

mikhawa commented Apr 2, 2018

from codewars.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment