How to Use PHP to Make a Switch for HTML5 and CSS3 Programming - dummies

How to Use PHP to Make a Switch for HTML5 and CSS3 Programming

By Andy Harris

Often, you run across a situation in HTML5 and CSS3 programming where you have one expression that can have many possible values. You can always use the structure to manage this situation, but PHP supplies another interesting option.

image0.jpg

The code for this program uses the switch structure. Take a look at how it’s done:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>switch.php</title>
</head>
<body>
<p>Ask the magic 8 ball a yes or no question!</p>
<?php
$yourNumber = rand(1,8);
switch($yourNumber){
case 1:
print "<p><img src="images/8ball1.png" alt = "fat chance" /></p>";