reverse.php
function reverse1($str1) {
$count = strlen($str1);
for ($i = $count - 1; $i >= 0; $i--) {
echo $str1[$i];
}
}
$str1 = "abcdef";
reverse1($str1);
reverse2.php
function reverse2($str2) {
$count = strlen($str2);
$num = $count - 1;
for ($i = 0; $i < $count / 2; $i++) {
$last = $str2[$i];
$str2[$i] = $str2[$num];
$str2[$num] = $last;
$num--;
}
echo $str2;
}
$str2 = "abcdef";
reverse2($str2);
reverse3.php
function reverse3($str3) {
$count = strlen($str3);
for($i = 0; $i < --$count; $i++) {
$last = $str3[$i];
$str3[$i] = $str3[$count];
$str3[$count] = $last;
}
echo $str3;
}
$str3 = "abcdef";
reverse3($str3);