Hi guys,
Lets do palindrome with php
Lets see what palindrome is
If a string is reversed and the reversed string is equal to the string given, then the given string is palindrome
Example
String = MOM
String_Reversed = MOM
The given string is palindrome.
Lets begin your code
<?php
// Declare a Variable
$string = "level";
echo "Given String is $string";
// Lets reverse the string
$reversed_string = strrev($string);
// Lets check whether our string is equal to our reversed string
if ($string == $reversed_string)
{
echo 'Wow it is a Palindrome';
}
else
{
echo 'Oops its not a Palindrome';
}
?>
It works like a charm right......!
Its cool right ?
Lets do palindrome with php
Lets see what palindrome is
If a string is reversed and the reversed string is equal to the string given, then the given string is palindrome
Example
String = MOM
String_Reversed = MOM
The given string is palindrome.
Lets begin your code
<?php
// Declare a Variable
$string = "level";
echo "Given String is $string";
// Lets reverse the string
$reversed_string = strrev($string);
// Lets check whether our string is equal to our reversed string
if ($string == $reversed_string)
{
echo 'Wow it is a Palindrome';
}
else
{
echo 'Oops its not a Palindrome';
}
?>
It works like a charm right......!
Its cool right ?
No comments:
Post a Comment