Question: Rewrite list.php from Chapter 7 so that it uses foreach instead of implode(), but still prints each sorted word on its own line in the
Rewrite list.php from Chapter 7 so that it uses foreach instead of implode(), but still prints each sorted word on its own line in the browser. Also, add some form validation so that it only attempts to parse and sort the string if it has a value.
HTML:
Enter the words you want alphabetized with each individual word separated by a space:
PHP:
// Address error management, if you want.
// Turn the incoming string into an array: $words_array = explode(' ' , $_POST['words']);
// Sort the array: sort($words_array);
// Turn the array back into a string: $string_words = implode(' ', $words_array);
// Print the results: print "
An alphabetized version of your list is: $string_words
";?>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
