belongs to collection: PHP Programs
A number can be written in reverse order.
For example
12345 = 54321
Logic:
Example:
Below progrem shows digits reversal of 23456.
<?php $num = 23456; $revnum = 0; while ($num > 1) { $rem = $num % 10; $revnum = ($revnum * 10) + $rem; $num = ($num / 10); } echo "Reverse number of 23456 is: $revnum"; ?>
Output:
Function strrev() can also be used to reverse the digits of 23456.
<?php function reverse($number) { /* writes number into string. */ $num = (string) $number; /* Reverse the string. */ $revstr = strrev($num); /* writes string into int. */ $reverse = (int) $revstr; return $reverse; } echo reverse(23456); ?>
Output:/strong>
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.
Reversing Number in PHP
Example:
Below progrem shows digits reversal of 23456.
Output:
Reversing Number With strrev () in PHP
Example:
Function strrev() can also be used to reverse the digits of 23456.
Output:/strong>
need an explanation for this answer? contact us directly to get an explanation for this answer