Here is a correct example for “Show What You Know!”, from the “Functions, Part I” section of the PHP course.
I have used food terms instead of friends.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <html> <p> <?php // Create an array and push on the names // of your closest family and friends $food = array("pizza", "fruits", "pepsi"); // Sort the list $sort = sort($food); array_push($food, "Hamburger"); // Randomly select a winner! $count_items = count($food); $random_winner = rand(0, $count_items-1); echo ''.$food[$random_winner].'<br>'; // Print the winner's name in ALL CAPS print strtoupper($food[$random_winner]); ?> </p> </html> |