logo CodeStepByStep logo

longest_string

Language/Type: PHP arrays string
Author: Melissa Hovik (on 2018/01/05)

Write a function named longest_string that accepts an array of Strings and returns the String that has the longest length. If more than one String in the array has the longest length, the function should return the String that occurs last in the array. If the passed array is empty, the function should return an empty String.

For example, if an array named $pokemon stores the following Strings:

["Pikachu", "Entei", "Mew", "Suicune", "Lugia", "Arcanine"] 

The call of longest_string($pokemon) should return "Arcanine".

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.