Now that we know the basics of PHP, see how many of the following tasks you can accomplish. Use the previous lesson as a resource.
Turn on your MAMP server, create a folder inside your MAMP working directory called php_exercises
, and create a file called index.php
. You will do all your work inside this file.
Once you have this file, go to http://localhost:8888
in your browser and navigate to your php_exercises
folder. This should show a blank page...but not for long!
- Get php to
echo
"Hello World!" - Replace
World
with a variable called$place
and use string concatenation toecho
the new string. - Get php to
echo
all numbers from 1 to 20 - Create a variable called $name, and save a string to it (your name or a friend's name)
- Create three
<p>
tags, one that says "Name Too Short", one that says "Name Long Enough", and one that says "Name Has No Length" - Using conditionals, have the
<p>
tags show up if $name is less than 5 characters, greater than or equal to 5 characters, and for any other case, respectively. - Create a class for
animal
with three properties. Echo these properties to the browser. Make sure you're using the right type of properties that allow you toecho
them outside of the class declaration. - Create a class for
cat
thatextends
animal
and has three additional properties. Echo all six ofcat
s properties to the browser. - Get php to
echo
three simple math problems and their solutions. - Create an array of 7 numbers, and print all the values out to page.
- Create an associative array of three names and their ages, and print all the names and ages out to page.