Trending News
Home / Web Development / PHP / Reverse a string without built in functions – PHP

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.

Loading Facebook Comments ...
Social Media Auto Publish Powered By : XYZScripts.com