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 In the world of web development, selecting the correct framework is critical. Laravel and…
Introduction By enabling containerization, Docker has transformed the way software is built, deployed, and managed.…
Introduction Speed and efficiency are critical in the ever-changing world of web development. Effective caching…
Introduction Git, a popular version control system in software development, enables developers to track changes,…
Introduction Are you tired of grappling with tangled changes and unfinished work while using Git?…
Introduction Version control is essential in software development because it ensures that changes to a…