logo CodeStepByStep logo


Language/Type: PHP arrays traversals

Write a function named remove_palindromes that that removes all strings that are palindromes from an array of strings.

Your function should accept an array of strings as a parameter and return a new array, replacing every string in the passed array that is a palindrome with an empty string, "". For example, if an array named $a stores the following element values:

$a = ["Madam", "raceCAR", "", "hi", "A", "Abba", "banana", "dog God",
      "STOP otto POTS", "Madame", "PHP", "LevEL", "staTS"];

Then the call of remove_palindromes($a) should return an array containing the following element values. Notice that the palindromes from the array such as "Madam" and "LevEL" have been replaced by "".

             ["", "", "", "hi", "", "banana", "", "", "Madame", "", "", ""]


  • Do not modify the passed array.

Note: You may want to go solve the string problem is_palindrome first and use it as part of your solution to this problem.

Function: Write a PHP function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.