PHP program to check whether a given number is palindrome or not

Here, we are executing a PHP program that will check whether a given integer number is palindrome or not.

Given a number and we need to check whether it is palindrome or not utilizing the PHP program.

Palindrome number

A number which is equivalent to its switch number is said to be a palindrome number.


    Number: 12321

    It is palindrome number

    Number is 12321 and its reverse number is 12321, 
    both are equal. Hence, it is a palindrome number.


    //function: isPalindrome
    function isPalindrome($number){
        //assign number to temp variable
        $temp = $number;
        //variable 'sum' to store reverse number
        $sum = 0;
        //loop that will extract digits from the last
        //to make reverse number
            $digit = $temp % 10;
            $sum = $sum*10 + $digit;
            $temp = $temp/10;
        //if number is equal to its reverse number
        //then it will be a palindrome number
        if($sum == $number)
            return 1;
            return 0;
    //Main code to test above function
    $num = 12321;
        echo($num . " is a palindrome number");
        echo($num . " is not a palindrome number");


12321 is a palindrome number

Leave a Comment

error: Alert: Content is protected!!