Skip to content

Instantly share code, notes, and snippets.

@harmenjanssen
Last active July 29, 2018 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harmenjanssen/24d2b40110fb5a30414029edf53d1431 to your computer and use it in GitHub Desktop.
Save harmenjanssen/24d2b40110fb5a30414029edf53d1431 to your computer and use it in GitHub Desktop.
Recursive function for grabbing the middle character (or 2) of a string.
<?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