Palindrome number Program in PHP


Prev Tutorial Next Tutorial

Palindrome number Program in PHP

Palindrome number means number remain same after reverse any number. For example we reverse 121 result will be 121 so it is palindrome number.

Steps to check number is palindrome or not

  • Take a number.
  • Reverse the input number.
  • Compare both the numbers.

Palindrome number Program in PHP

<?php

$num = 121;
$p=$num;
$revnum = 0;
while ($num != 0)
{
$revnum = $revnum * 10 + $num % 10;
//below cast is essential to round remainder towards zero
$num = (int)($num / 10); 
}
 
if($revnum==$p)
{
echo $p," is Palindrome number";
}
else
{
echo $p." is not Palindrome number";
}

?>

Output

	
121 is Palindrome number

Prev Tutorial Next Tutorial

Download Projects

Google Adsense Advertisements
Free Classified Site – Bedpage

Yahoo Advertisements