Last active
September 8, 2021 13:19
-
-
Save LarrySul/160291881601eb76d7bfbfe69d7081c8 to your computer and use it in GitHub Desktop.
Write a function that can be used to reverse a string in php
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 reverse_string($str) : string | |
{ | |
if(!is_string($str)) return "not a string"; | |
$lengthString = strlen($str); | |
$data = []; | |
for($i = ($lengthString -1); $i >=0; $i--){ | |
$data[] = $str[$i]; | |
} | |
return implode("", $data); | |
} | |
print_r(reverse_string("John Peich")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment