Created
November 12, 2016 05:49
-
-
Save rajvanshipradeep15/87cc27e3d524798726d3e2de85dea099 to your computer and use it in GitHub Desktop.
reverse string with max N 2 iteration
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 reverse($str) | |
{ | |
for ($i = 0, $j = strlen($str) - 1; $i < $j; $i++, $j--) { | |
$tmp = $str[$i]; | |
$str[$i] = $str[$j]; | |
$str[$j] = $tmp; | |
$iteration++; | |
} | |
echo $iteration; | |
return $str; | |
} | |
echo reverse('pradeep'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment