To reverse a number in PHP without the use of integrated function. First we want to claim a variable to save the reversed number, and first of all assign 0 value to it. Now, extract the final digit from the unique number, and multiply the opposite number with 10, then add the extracted digit to reversed number, and divide the unique number by 10.
A number can be written in reverse order.
For example
12345 = 54321
/* PHP program to reverse a number without using function */
$num = 12345;
$revnum = 0;
while ($num != 0)
{
$a = $num % 10;
$revnum = ($revnum * 10) + $a
//below cast is essential to round remainder towards zero
$num = (int)($num / 10);
}
echo "Reverse number: $revnum\n";
In the above example we reverse the number without using PHP function. This is very important technical php interview questions you should know this trick to reverse the number.
Now we look using PHP function reverse the number
$num = 1234567;
$rev = strrev($num);
echo "original number is = <b> $num </b> <br/>";
echo "reverse number is = <b> $rev </b> <br/>";
Password Strength Checker Using JavaScript
How To Find Reverse A Number In Python
Introduction Git tags are an essential feature of version control systems, offering a simple way…
Introduction The methods that browsers employ to store data on a user's device are referred…
Introduction A well-known open-source VPN technology, OpenVPN provides strong protection for both people and businesses.…
Introduction Integrating Sentry into a Node.js, Express.js, and MongoDB backend project significantly enhances error tracking…
Introduction In the world of JavaScript development, efficiently managing asynchronous operations is essential. Asynchronous programming…
Introduction Let's Encrypt is a Certificate Authority (CA) that makes it simple to obtain and…