How to reverse a string without using Loops and Builtin Function in PHP

Do you know how to reverse a string without using any loops or built in function in php?

There is an amazing recursive function will do this magic trick.

See the below lines of codes:


<?php

function myreverse($str)
{
return $str?myreverse(substr($str,1)).$str[0]:'';
}
echo myreverse("SUPERMAN");

?>

The above function will give the reverse result. Just pass the parameter.

 

2 Comments

Add a Comment

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