To practice your new PHP skills, you’re going to build a new dynamic PHP-powered page to display information about a few different vehicles.
1. Create a new PHP page to display information about a few cars
Create a new
vehicle.php page in your
Add the basic HTML page code to this file. (Reference one of your other HTML/PHP page files for guidance.)
2. Create two PHP arrays at the top of your page, both named
These arrays will each store information about a vehicle — the first one should contain information about a car, and then second should contain information about a truck. (Just pick a car and a truck, or make up some information.)
Each array should contain 3 pieces of information:
3. Implement a
type request variable
type request variable should be set to either
truck, designating whether to display the car’s information or the truck’s information.
Use PHP to retrieve the value of the
type request variable.
4. Set the
$vehicle array based on the value of
if/elseif statement to do this.
(And remember to create your empty array above the
if/elseif to prevent errors in the case an erroneous
type value is supplied! OR Get Bonus Points: You can include an
else clause at the end of your
if/elseif statement; use that to supply your empty array instead.)
5. Print out the vehicle information on the page
echo statements to do this.
You should now have a new, dynamic PHP page!