Palindrome Number in PHP


Q. Write a PHP program to check Palindrome Number or Not

<?php
// Define the number
$originalNumber = 121;
$number = $originalNumber;
$reverse = 0;

// Reverse the number
while ($number > 0) {
    $digit = $number % 10;
    $reverse = ($reverse * 10) + $digit;
    $number = (int)($number / 10);
}

// Check if the original and reversed numbers are the same
if ($originalNumber == $reverse) {
    echo "$originalNumber is a Palindrome number.";
} else {
    echo "$originalNumber is NOT a Palindrome number.";
}
?> 

Q. Write an algorithm to check Palindrome Number in PHP

1. Start
2. Define a number as originalNumber
3. Copy originalNumber to number and set reverse = 0
4. Repeat while number > 0:
    a. digit = number % 10
    b. reverse = reverse * 10 + digit
    c. number = number / 10
5. If originalNumber == reverse, print "Palindrome"
6. Else, print "Not a Palindrome"
7. End 



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.