Skip to content

Instantly share code, notes, and snippets.

@ibrahimkholil
Created October 13, 2018 11:50
Show Gist options
  • Save ibrahimkholil/09f610ca2fadcedb27f048063177698c to your computer and use it in GitHub Desktop.
Save ibrahimkholil/09f610ca2fadcedb27f048063177698c to your computer and use it in GitHub Desktop.
Palindrome number in php
function checkPalindrome($inputString) {
echo $inputString[0] == $inputString[(strlen($inputString) - 1)] ? 'Its palindrom' : 'Its not';
}
checkPalindrome(abbab);
second way:
function checkPalindrome($inputString) {
$str = $inputString;
$rev = 0;
while($str > 0){
$output = $str % 10;
$rev = ($rev * 10)+$output;
$str = $str/10;
}
if($str == $rev){
echo "this is palindrome " .$inputString;
}
else{
echo "this is not palindrome";
}
}
checkPalindrome(abbab);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment