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:

I Must Sort This Out!

Enter the words you want alphabetized with each individual word separated by a space:

PHP:

I Have This Sorted Out

// 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!