PHP Program to Check Palindrome Number

What is Palindrome Number?

A palindrome number is a number that remains the same when its digits are reversed. For example, 55 is a palindrome number.

Note: The reverse of 55 is also a 55. Hence, 55 is a palindrome number.

Tips: It is recommended to use our online Palindrome Numbers calculator for better understanding.

Check Palindrome Number

In the following example, we will check whether the given number (121) is a Palindrome number or not.

Example

PHP Compiler
<?php $num = 121; $copyNum = $num; $reverse = 0; // reverse a number while($copyNum != 0) { $reverse = $reverse * 10; $reverse = $reverse + ($copyNum % 10); $copyNum = floor($copyNum / 10); } // result if($num == $reverse) echo "$num is a palindrome number"; else echo "$num is not a palindrome number"; ?>

Palindrome Numbers between the Given Range

In the following example, we will find all the Palindrome numbers between 10 and 50.

Example

PHP Compiler
<?php $start = 10; $end = 50; echo "Palindrome numbers between $start and $end: <br>"; for($start=$start; $start<=$end; $start++) { $copyNum = $start; $reverse = 0; // reverse a number while($copyNum != 0) { $reverse = $reverse * 10; $reverse = $reverse + ($copyNum % 10); $copyNum = floor($copyNum / 10); } // result if(($start == $reverse) && ($start != 0)) { $flag = 1; echo "$start "; } } if($flag == 0) echo "There is no palindrome number between the given range"; ?>

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author