Skip to content

Instantly share code, notes, and snippets.

@mirzalazuardi
Last active January 18, 2019 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirzalazuardi/b6da1188d1fd1d2042da39611b1757dc to your computer and use it in GitHub Desktop.
Save mirzalazuardi/b6da1188d1fd1d2042da39611b1757dc to your computer and use it in GitHub Desktop.
PHP #1
<?php
/**A palindrome is a word that reads the same backward or forward. Write a function that checks if a given word is a palindrome.
* Character case should be ignored. For example, isPalindrome("Deleveled") should return true as character case should be ignored, resulting in "deleveled", which is a palindrome since it reads the same backward and forward.
**/
class Palindrome
{
public static function isPalindrome($word)
{
$word = trim($word);
$word = strtolower($word);
$chr_word = str_split($word);
$chr_word_rsv = array_reverse($chr_word);
return ($chr_word_rsv == $chr_word) ? true : false;
}
}
echo Palindrome::isPalindrome('level'); //palindrome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment