PHP Program to Reverse a String using For loop
ADVERTISEMENTS
PHP program to reverse a string using for loop. In this article, you will learn how how to make a PHP program to reverse a string using for loop.
String Conversion
"abcd" after reverse ==> "dcba"
Source Code
<?php
// PHP Program to Reverse a String using For loop
$x = "hello world";
echo "The input string is: ", $x, "\n\n";
echo "The reverse of the string is: ";
for ($i = (strlen ($x) - 1); $i >= 0; $i--) {
echo $x[$i];
}
echo "\n";
?>
Output
The input string is: hello world
The reverse of the string is: dlrow olleh