# Reverse Number In PHP Example

This post was last updated on December 9th, 2023 at 06:57 am

Hi dev,

Today, i show you reverse number in PHP example. This article will give you simple reverse number in PHP example. you will reverse number in PHP example. In this article, we will implement a reverse number in PHP example.

It is a straightforward illustration of how to utilise PHP’s strrev() function. The idea behind how to use PHP’s strrev() function is clear. If you’re wondering how to reverse numbers in PHP, I’ll provide a straightforward example and a solution.

So, let’s follow few steps to create example of reverse number in PHP example.

### Example 1: Reverse number in PHP without using any function PHP

```<!DOCTYPE html>
<html lang="en">
<title>Reverse number in PHP without using any function PHP - codeplaners </title>
<body>
<h4>Reverse number in PHP without using any function PHP - codeplaners </h4>

<?php
//define a variable and assign value
\$num = 23456;

//define variable and initialize with 0
\$revNo = 0;

// iterate with loop
while (\$num > 1)
{
// Multiply the reverse number by 10, and add the remainder which comes after dividing the number by 10.

\$rem = \$num % 10;
\$revNo = (\$revNo * 10) + \$rem;
\$num = (\$num / 10);
}
//Print the reversed number
echo "Reverse number of 23456 is: \$revNo";
?>

</body>
</html>
```

Output:

```Reverse number of 23456 is: 65432
```

### Example 2: Reserve a number with using strrev() function in PHP

```<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<title>Reverse number in PHP with using strrev() function PHP - codeplaners </title>
<body>
<h4>Reverse number in PHP with using strrev() function PHP - codeplaners </h4>

<?php
\$number = 123456;
echo "Reverse number of \$number is " .strrev( \$number );
?>

</body>
</html>
```

Output:

```Reverse number of 123456 is 654321
```

I hope it will assist you…