CodesJava

Easy learning with example program codes

PHP program to reverse a number

PHP program to reverse a number:

The below program can be used to reverse a given number using a loop. The PHP echo statement is used to output the result on the screen.

Reverse Number of 123456789= 987654321.
Example

<!DOCTYPE html>
<html>
<body>
 
<?php  
 
$num = 123456789;  
$x = 0;
$n =$num;
 
while(floor($num))
{  
$mod = $num%10;
$x = $x * 10 + $mod;  
$num = $num/10;
}  
echo "Reverse of $n is $x.";
?>
 
</body>
</html>

Output

Reverse of 123456789 is 987654321.
Please follow and like us:
error
Posted in PHP   








Copyright © 2019 CodesJava DMCA.com Protection Status