Time for you to practice some arrays and foreach loops!
- Create an array of your friends' names and print to the browser that each of them is your friend (for example,
<h1>Moriah is my friend.</h1>).
- Create an array of the names of your favorite writers. Then use a foreach loop to print them to the browser with their letters reversed.
- Create an array of numbers and multiply them together. Remember not to use quotes around the numbers so you can do arithmetic with them! Hint: Instead of creating a blank string, like we did for
$list, you can create a variable called
$solution and start by setting it equal to 1. Since anything multiplied by 1 is itself, you can then safely say something like:
$solution = $solution * $next_number;
- Create a cash register website with a form where your user enters up to 5 numbers representing the prices of 5 items purchased from their store. Then display the sum of all the numbers entered into the form. Hint: Watch out for undefined variables. What happens if your user only inputs 2 numbers and leaves the rest of the form fields blank? Be sure to set default values for your variables.