Palindrome Number Program in PHP
The palindrome number means the number will be the same after reversing any number. For example, we reverse the 151 results will be 151 so it is a palindrome number.
Note: If equal, it means the number is a palindrome
<?php
$origNumber = 151;
$tempNumber=$origNumber;
$revNumber = 0;
while($tempNumber != 0){
$revNumber = $revNumber * 10 + $tempNumber % 10;
$tempNumber = (int)($tempNumber / 10);
}
if($revNumber==$origNumber){
echo $origNumber." is Palindrome number";
}
else{
echo $origNumber." is not Palindrome number";
}
?>
Output:151 is Palindrome number
<?php
$origNumber = 365;
if(checkPalindrome($origNumber)==$origNumber){
echo $origNumber." is Palindrome number";
}else{
echo $origNumber." is not Palindrome number";
}
function checkPalindrome($checkNumber){
$tempNumber=$checkNumber;
$revNumber = 0;
while($tempNumber != 0){
$revNumber = $revNumber * 10 + $tempNumber % 10;
$tempNumber = (int)($tempNumber / 10);
}
return $revNumber;
}
?>
Output: 365 is not Palindrome number
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning