• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Catatan PHP Function to Find Palindrome

Kepala Suku

Web & Mobile Developer
Staff member
Write a PHP function that checks whether a passed string is a palindrome or not?
A palindrome is word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run.
function is_palindrome($string){
   return strrev($string)==$string?true:false;
Example of use above function:
echo is_palindrome("kayak"); //return true
echo is_palindrome("kayak")?"Great! That's palindrome!":"No! It's not palindrome";
echo is_palindrome("palindrome"); //return false
echo is_palindrome("palindrome")?"Great! That's palindrome!":"No! It's not palindrome";