Write a PHP program to reverse the digits of an integer.
<?php function reverse_integer($n) { $reverse = 0; while ($n > 0) { $reverse = $reverse * 10; $reverse = $reverse + $n % 10; $n = (int)($n/10); } return $reverse; } print_r(reverse_integer(1234)."\n"); print_r(reverse_integer(23)."\n"); ?>
Sample Output:
4321 32
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer