Created
October 13, 2018 11:50
-
-
Save ibrahimkholil/09f610ca2fadcedb27f048063177698c to your computer and use it in GitHub Desktop.
Palindrome number in php
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
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