w3resource
php Programming Exercies

PHP function Exercises: Checks whether a passed string is a palindrome or not

PHP function: Exercise-6 with Solution

Write a PHP function that checks whether a passed string is a palindrome or not?

A palindrome is word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run.

Pictorial Presentation:

PHP function Exercises: Checks whether a passed string is a palindrome or not

Sample Solution:

PHP Code:

<?php
function check_palindrome($string) 
{
  if ($string == strrev($string))
      return 1;
  else
	  return 0;
}
echo check_palindrome('madam')."\n";
?>

Sample Output:

1

Flowchart :

Flowchart: Checks whether a passed string is a palindrome or not

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP function that checks if a string is all lower case.
Next: PHP Regular Expression Exercises Home

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming