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. |