By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: Palindrome Integers - PHP Function Task

+2 votes

A palindrome is a number which reads the same backward as forward, such as 323 or 1001. Write a program which reads a positive integer numbers until you receive "END", for each number print whether the number is palindrome or not.


palindrome integers

asked in PHP category by user andrew

1 Answer

+1 vote

I've used strrev() php function for this task; Here is my solution:

$input = readline();

while ($input != "END") {
    echo isPalindrome($input);//echo the function isPalindrome()
    $input = readline();

function isPalindrome($str) {
    if ($str === strrev($str)) {
        $result = "true" . PHP_EOL;
    } else {
        $result = "false" . PHP_EOL;
    return $result;
answered by user samfred5830