Last active
July 29, 2018 07:33
-
-
Save harmenjanssen/24d2b40110fb5a30414029edf53d1431 to your computer and use it in GitHub Desktop.
Recursive function for grabbing the middle character (or 2) of a string.
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 | |
function middle_char(string $str): string { | |
return strlen($str) <= 2 | |
? $str | |
: middle_char(substr($str, 1, -1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment