PHP program to check palindrome number using while loop or not using function of any number
ADVERTISEMENTS
PHP program to check palindrome numbers using a while loop or not using a function of any number. This is the program to check an integer number is a palindrome or not?
What is a palindrome?
A palindrome is a case where if the reverse of any number will be matched correctly with its original integer number, It will be a palindrome.
Case example:
7997 == 7997 => a palindrome
Let us understand this concept through a php program example:
<?php
// PHP program to check the palindrome of any integer number using the while loop
$x = 90009;
$r = 0;
$rN = 0;
$oN = 0;
// $rN - denotes reverse number
// $oN - denotes original number
// $r - denotes remainder
$oN = $x;
// this reverse number will be stored during iteration
while ($x!= 0) {
$r = $x % 10;
$r = $r >= 1 ? $r : 0;
$rN = $rN * 10 + $r;
$rN = $rN ? round ($rN) : 0;
$x /= 10;
$x = $x >= 1 ? $x : 0;
}
// if the original number will match with reverse then the palindrome case will be true
if ($oN == $rN)
echo $oN, " is a palindrome number.";
else
echo $oN, " is not a palindrome number!";
?>
Output:
Enter an integer number::
90009
This 90009 is a palindrome number.
Tags:
1. write a program in php to given number is palindrome or not
2. armstrong number program in php
3. php program to reverse a number
4. write a program in php to given number is "armstrong" or not