- Assign the given string to the variable
- Calculate the length of the string
- Declare a variable in which you have to store the reversed string
- Iterate the string using for loop with appropriate looping and count
- Concatenate the string inside the for loop
- Display the reversed string.
<?php $string = 'Mydons'; // string to be reversed $string_length = strlen($string); // finding string length $reversed_string = ''; // store the reversed string for($i=$string_length;$i>-1;$i--){ // iterating to reverse the string $reversed_string .= $string{$i}; } echo 'The reversed string is <hr/>'.$reversed_string; // output will be 'snodyM' ?>
The post How to reverse a string in PHP without strrev(inbuilt) and Array function appeared first on Mydons.