Hi All,
Here i have added the simple way to find a Palindrome using String Function.
<?php
// Palindrome using String function
$str = "1441";
$str1 = "12521";
$str2 = "MALAYALAM";
$str3 = "Game";
$strrev = strrev($str2);
if($str2 === $strrev){
echo $strrev ." is Palindrome"."</br>";
}else{
echo $str2. " Not a Palindrome"."</br>";
}
$strrev1 = strrev($str1);
if($str1 === $strrev1){
echo $strrev1 ." is Palindrome"."</br>";
}else{
echo $str1. " Not a Palindrome"."</br>";
}
$strrev2 = strrev($str);
if($str === $strrev2){
echo $strrev2 ." is Palindrome"."</br>";
}else{
echo $str. " Not a Palindrome"."</br>";
}
$strrev3 = strrev($str3);
if($str3 === $strrev3){
echo $strrev3." is Palindrome"."</br>";
}else{
echo $str3. " Not a Palindrome"."</br>";
}
?>
OUTPUT:
MALAYALAM is Palindrome
12521 is Palindrome
1441 is Palindrome
Game Not a Palindrome
No comments:
Post a Comment