Last active
May 24, 2018 17:40
-
-
Save Cvetomird91/4d693314aaf3283c10657d47d9d10393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Palindrome | |
{ | |
public static function isPalindrome($word) | |
{ | |
$temp = ''; | |
$word = lcfirst($word); | |
$length = strlen($word); | |
for ($i = $length; $i >= 0; --$i) { | |
@$temp .= $word[$i]; | |
} | |
return ($word === $temp); | |
} | |
} |
Here's the refactor with strrev:
`<?php
class Palindrome
{
public static function isPalindrome($word)
{
return (strtolower($word) === strtolower(strrev($word)));
}
}
echo Palindrome::isPalindrome('exe');
echo Palindrome::isPalindrome('Ini');`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this, It didn't come to my mind at first. :)