Reverse Number in PHP
Q. Write a PHP program to reverse a number
<?php
// Define the number
$number = 12345;
$reverse = 0;
$temp = $number;
// Reverse the number using a loop
while ($temp > 0) {
$digit = $temp % 10;
$reverse = $reverse * 10 + $digit;
$temp = (int)($temp / 10);
}
// Display the result
echo "Original number: $number<br>";
echo "Reversed number: $reverse";
?>
Q. Write an algorithm to reverse a number in PHP
1. Start
2. Define an integer number
3. Set reverse = 0 and temp = number
4. Repeat while temp > 0:
a. digit = temp % 10
b. reverse = reverse * 10 + digit
c. temp = temp / 10
5. Print reverse
6. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com