Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

How to print the number in reverse order in PHP embedded in HTML? -4

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:

  1. 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.
  2. $rem is then added to the variable $rev after multiplying it by 10.
  3. Multiplication by 10 adds a new place in the $rev contains. $rev contain like this 0 * 10 + 3 = 3.
  4. $num is then divided by 10 so that now it only contains first two digits: 12.
  5. After second iteration, $rem equals 2, $rev equals 3 * 10 + 2 = 32 and $num = 1.
  6. After third iteration, $rem equals 2, $rev equals 32 * 10 + 1 = 321 and $num = 0.
  7. Now, $num will be existed outside the while loop and $rev contains 321.

Now , look at this coding

Input : 12345

Output :54321

Thanks

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.