How to print the number in reverse order in PHP?
In this program, you’ll learn to reverse a number using a while loop.
Logic:
- First of all, the remainder of $num divided by 10 is stored in the variable $rem. Now, $rem contains the last digit of $num, i.e. 3.
- $rem is then added to the variable $rev after multiplying it by 10.
- Multiplication by 10 adds a new place in the $rev contains. $rev contain like this 0 * 10 + 3 = 3.
- $num is then divided by 10 so that now it only contains first two digits: 12.
- After second iteration, $rem equals 2, $rev equals 3 * 10 + 2 = 32 and $num = 1.
- After third iteration, $rem equals 2, $rev equals 32 * 10 + 1 = 321 and $num = 0.
- Now, $num will be existed outside the while loop and $rev contains 321.
Now , look at this coding
Input : 12345

Thanks
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals