Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rajvanshipradeep15/87cc27e3d524798726d3e2de85dea099 to your computer and use it in GitHub Desktop.
Save rajvanshipradeep15/87cc27e3d524798726d3e2de85dea099 to your computer and use it in GitHub Desktop.
reverse string with max N 2 iteration
<?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