Copied!
PHP

Check Palindrome Number in PHP

check-palindrome-number-in-php
Shahroz Javed
Jul 28, 2025 . 36 views

Table Of Contents

 
 

1. Introduction

A palindrome number is a number that remains the same when its digits are reversed. For example, 12121 is a palindrome because reversing it still gives 12121.

2. PHP Code to Check Palindrome

$number = 12121;
$x = $number;
$reversed = 0;

while ($number > 0) {
    $digit = $number % 10;
    $reversed = $reversed * 10 + $digit;
    $number = floor($number / 10);
}

if ($x == $reversed) {
    echo "Palindrome";
} else {
    echo "Not a palindrome";
}
    

3. Explanation

The code reverses the given number and compares it with the original. If both match, the number is a palindrome. Otherwise, it’s not.

💡 Related: Check out our guide on String Palindrome in PHP.

11 Shares

Similar Posts