How to reverse a string without using strrev() in PHP

1 Answer

0 votes
$str = "Programming";

$len = strlen($str);  

for ($i = 0, $j = $len - 1; $i <= $len / 2; $i++, $j--) {
    $ch = $str[$i];
    $str[$i] = $str[$j];
    $str[$j] = $ch;
}

echo $str;
 
 
 
 
 
/*
run:
 
gnimmargorP
 
*/

 



answered Aug 23, 2021 by avibootz
...