Reverse number program in PHP using for loop
Last updated:6th Jul 2022
In this program, you will find the reverse of the number by using for loop.
<?php
$n=1345;
$copy=$n;
$rev=0;
for(;$n>0;$n=(int)($n/10))
{
/*It will find the reverse of the number.*/
$rev=$rev*10+$n%10;
}
echo "reverse of number $copy is:$rev";
?>
output
reverse of number 1345 is:5431
Related Program
- Palindrome program in PHP
- Fibonacci Series in PHP by using for loop and HTML form
- Program to Check whether number is Even or Odd in PHP
- Factorial program in PHP by using for loop, while loop, and do-while loop
- Check user entered year is leap year or not in PHP
- Check whether a number is a prime number or not in PHP
- Reverse number program in PHP by using library function or without library function
- PHP program to greet the user based on time
- Write a PHP program to print the sum of digits