Created
May 15, 2019 08:16
-
-
Save arbaieffendi/05ee1c62c3fbb33e4ec1fd7e8a15a2ad to your computer and use it in GitHub Desktop.
Palindrome Class written in PHP 7.1.9. - isPalindrome
This file contains hidden or 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) | |
{ | |
$word = strtolower($word); | |
$wordArray = str_split($word); | |
for ($i = 0; $i <= count($wordArray); $i++) { | |
$wordBackward = $wordBackward.$wordArray[count($wordArray)-$i]; | |
} | |
//echo "Forward : ".$word."\n"; | |
//echo "Backward : ".$wordBackward."\n"; | |
if ($word == $wordBackward) | |
return true; | |
else | |
return false; | |
} | |
} | |
echo Palindrome::isPalindrome('Deleveled'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment