Objective

Create a function to test whether a given word is a palindrome or not.

Difficulty

Easy

Description

A palindrome is a word that reads the same forwards and backwards.

For example, 'ada' is a palindrome. If you read it forwards, it's 'ada'; and similarly, if you read it backwards, it's still 'ada'. Since it's the same in both directions, it's a palindrome.

Now, consider the word 'bulb'. Forwards, it's read as 'bulb'. But backwards, it's read as 'blub'. Since both these directions yield different words, 'bulb' is not a palindrome.

By this means, every single letter is a palindrome as well. 'a' is a palindrome, 'b' is a palindrome, and so on and so forth.

In this exercise, you have to create a program that asks the user to enter a word, and then outputs backs 'Yes' if it is a palindrome, or otherwise 'No'.

The input prompt asking for the word shall be as follows:

Enter a word: <word>

where <word> denotes the word entered by the user to be run against a palindrome check.

Shown below are two examples:

Enter a word: ada Yes
Enter a word: Ada No
Enter a word: bulb No

Note that you must create a function is_palindrome() for this exercise.

The function should have the following signature:

<?php

function is_palindrome($word) {
   // Code here.
}

It must return true is the given $word is a palindrome, or else false.

Moreover, as can be seen in the second example above, is_palindrome() must operate case-sensitively i.e. 'Ada' should not be considered as a palindrome because the beginning and ending characters aren't of the same case.

Hints