PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 17: Write a PHP program check a function to reverse a string.

reverse_string.php

<!DOCTYPE html>
<html>
<head>
	<title>PHP Progarms TutorialDuniya.com</title>
</head>
<body>
	<?php
		function reverse_string($str1)
		{
			$num = strlen($str1);
			if($num == 1)
			{
				return $str1;
			}
			else
			{
				$num--;
				return reverse_string(substr($str1 ,1, $num)) . substr($str1, 0, 1);
			}
		}
		print_r(reverse_string('REST') . "\n");
	?>
</body>
</html>



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.