logo CodeStepByStep logo

move_to_end

Language/Type: PHP recursion string return

Write a recursive function named move_to_end that accepts a string $s and a character $c as parameters, and returns a new string similar to $s but with all instances of $c moved to the end of the String.

The relative order of the other characters should be unchanged from their order in the original string $s. If the character is a letter of the alphabet, all occurrences of that letter in either upper or lowercase should be moved to the end and converted to uppercase.

If $c is a string that does not have a length of 1, your function should throw an Exception with the message, "Error: second argument must be a single-character string." Otherwise, if $s does not contain $c, it should be returned unmodified.

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.