PHP Program to Reverse a Numbers



In this post I am going to describe the PHP Program which tell us how to Reverse a number. Reversing a number means printing a number in reverse order eg if a number is as 1234 then after reversing it will be printed as 4321.

<?php
if(isset($_POST['submit'])){
	$number= $_POST['number'];
	$rev=0;
	while($number>=1){ //loop to check the digits in number
		$ln=$number%10; //taking last digit out from the number
		$number=$number/10; //modifying the value of number variable
		$rev=$rev*10;
		$rev=$rev+$ln; //Adding the number at once place
	}
	echo "Reverse number is ".$rev;
}
?>
<html>
	<head>
		<title>Reverse</title>
	</head>
	<body>
		<form action="" method='POST'>
		<label for="number">Please Enter a Number</label>
		<input type="text" name="number" value="">
		<br><br>
		
		<input type="submit" value="Done" name="submit">
		</form>
	</body>
</html>

Program Output:

Stay tuned for the PHP Magento, WordPress and Magento2 latest tutorial and updates, Hope you enjoyed reading, if you need the professional Magento Development / PHP we can help you, just Click on the Link and send me your requirements.

Please Like the Post on Facebook or Google+.