PHP – Reverse a string without using string function!

There are several ways you can reverse a string in PHP. One is using default function and the 2nd way is without using default function.

Here is the one using default PHP reverse function:

Syntax:

string strrev ( string $string )

Example:

<?php

$str = "RADIO";

echo strrev ( $str );

?>

Without using default string functions:

<?php

//your string
$string = 'TEST';

//find string length
$len 	= strlen($string);

//loop through it and print it reverse
for ( $i = $len - 1; $i >=0;$i-- )
{
  echo $string[$i];
}
?>

You got how it is working now?. Enjoy then.

 

 

2 thoughts on “PHP – Reverse a string without using string function!”

Leave a Comment

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

Scroll to Top