Reverse a string without built in functions – PHP

Hi all,
Here I share one useful topic related to reverse a string without using inbuilt function.
Reverse a string in PHP is very simple and easy understand. Also PHP provides inbuilt function to reverse a string. The ‘strrev()’ function helps to reverse the string in PHP.




Eg:

<?php
echo strrev(“Helllo World”);
?>

OUTPUT

dlroW olleH

Reverse string without strrev

Next, how to reverse the given string in PHP without using inbuilt function(strrev). For reverse a string first we follow some seps: first assign the given string to a variable and calculate the length of the variabe, 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.

CODE








If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Leave a Reply

Your email address will not be published. Required fields are marked *