PHP program to reverse the number entered by the user, then displays the reversed number on the screen.
For example, if the user enters 678 as input, 876 is displayed as output. We use the mod(%) operator in the program to get the digits of an integer.
PHP Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php function reverse($number) { $rnum = 0; while ($number > 0) { $rnum = $rnum * 10; $rnum = $rnum + $number % 10; $number = (int)($number/10); } return $rnum; } print_r(reverse(1234)."\n"); ?> |