You are here: Home / Topics / PHP Program for checking Palindrome number

PHP Program for checking Palindrome number

Filed under: PHP on 2022-11-16 13:41:54

The below program checks for a Palindrome number using a loop. The PHP echo statement is used to output the result on the screen. A number is called as a Palindrome number if the number remains same even when its digits are reversed.

Palindrome Number:

abcde = edcba

Example: 24142, 1234321, etc.
Example

<!DOCTYPE html>
<html>
<body>

<?php  

$num = 123454321;  
$x = 0;
$n =$num;

while(floor($num))
{  
$mod = $num%10;
$x = $x * 10 + $mod;  
$num = $num/10;
}  

if($n==$x)
{  
echo "$n is a Palindrome number.";  
}

else
{  
echo "$n is not a Palindrome number.";  
}  
?> 

</body>
</html>
 

Output:

123454321 is a Palindrome number.

About Author:
V
Vishal Gupta     View Profile
Hi, I am Vishal Gupta. I like this Website for learning MCQs. This website is good for preparation.