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
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.

Related Posts

Ansible: Deep Dive into Jinja2 Ansible Template with example

Introduction to Ansible Templates and Jinja2 Ansible templates are powerful tools for creating dynamic configuration files and scripts based on variables and logic. Templates in Ansible use…

Read More

Complete User Guide for 404 Errors

Introduction A 404 error (also known as “404 Not Found”) is an HTTP status code indicating that a requested webpage cannot be found on the server. This…

Read More

What is CodeIgniter and use cases of CodeIgniter?

What is CodeIgniter? CodeIgniter is an open-source PHP web application framework designed to simplify and accelerate web development. It follows the Model-View-Controller (MVC) architectural pattern and provides…

Read More

What is SQL Server and use cases of SQL Server?

What is SQL Server? SQL Server, developed by Microsoft, is a relational database management system (RDBMS) that is designed to store and retrieve data requested by other…

Read More

Terrafrom – Example Code for remote-exec, local-exec & file provisioner

Rajesh Kumar I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at…

Read More

What is SQL and use cases of SQL?

What is SQL? SQL stands for Structured Query Language. It is a powerful programming language that allows users to interact with relational databases. It provides a standardized…

Read More