How to Reverse Number In PHP?

03-Apr-2023

.

Hi Dev,

This tutorial is focused on how to reverse numbers in PHP. you'll learn how to use strrev() function in PHP. We will use how to reverse numbers using PHP. if you have a question about how to use the strrev() function using PHP then I will give a simple example with a solution.

Now, let's see the article on how to reverse numbers using PHP. it's a simple example of how to use the strrev() function using PHP. you can understand the concept of how to use the strrev() function in PHP. if you have a question about how to reverse numbers in PHP then I will give a simple example with a solution.

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 </title>
<body>
<h4>Reverse number in PHP without using any function PHP </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>
```

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

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

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

</body>
</html>
```