Skip to content

Instantly share code, notes, and snippets.

@Cvetomird91
Last active May 24, 2018 17:40
Show Gist options
  • Save Cvetomird91/4d693314aaf3283c10657d47d9d10393 to your computer and use it in GitHub Desktop.
Save Cvetomird91/4d693314aaf3283c10657d47d9d10393 to your computer and use it in GitHub Desktop.
<?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);
}
}
@Cvetomird91
Copy link
Author

Thank you for this, It didn't come to my mind at first. :)

@Cvetomird91
Copy link
Author

Cvetomird91 commented May 26, 2017

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