[Solved] Palindrome Integers - PHP Function Task

  

3
Topic starter

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.

Examples:

palindrome integers

1 Answer
2

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

<?php
$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;
}
Share: