In Class Code from 10/9
<?php
/*printf(“My name is %s. I’m %d years old, which is %X in hexadecimal”, ‘Simon’, 33, “white”);
printf(“The result is: $%.2f”, 123.42 / 12);
$currTime = time() + (7 * 24 * 60 * 60);
echo “<br>” . $currTime;
//1412893018
//1412893028
for($i = 1; $i <= 12; $i++){
echo “$i * $i = ” . ($i * $i) . “<br/>”;
}*/
?>
<html>
<head>
</head>
<body>
<?php
/* if($_POST[‘doweek’] != “”){
$day = $_POST[‘doweek’];
switch ($day) {
case “Monday”:
echo “Laugh on Monday, laugh for danger.”;
break;
case “Tuesday”:
echo “Laugh on Tuesday, kiss a stranger.”;
break;
case “Wednesday”:
case “Thursday”:
case “Friday”:
case “Saturday”:
default: echo “Sorry you didn’t list one of our days.”;
}
} else {
echo ‘<form method=”post” action=”109_inclass.php”>
<input type=”text” name=”doweek” />
<button type=”submit” name=”submit”/>
</form>’;
}*/
$transportation = array(“car”, “jet”, “ferry”, “subway”);
if(isset($_POST[‘trans’]){
$usr_trans = explode(‘,’, $_POST[‘trans’]);
$transportation = array_merge($transportation, $usr_trans);
}
echo “Travel takes many forms, whether across town, across the country, or around the world. Here is a list of some common modes of transportation:”;
echo “<ul>”;
//if numerically indexed you can use a for or while loop to go through the whole item. sizeof will figure out how long your array is and stop when it reaches the end.
for($i = 0; $i < sizeof($transportation); $i++){
echo “<li>” . $transportation[$i] . “</li><br>”;
}
echo “</ul>”;
//other types of arrays including numeric can be done using the foreach loop instead. Useful for associative arrays
/*foreach($transportation as $mode){
echo “<li>” . $mode . “</li><br>”;
}*/
echo “Please add other modes of transportation. Separate each with a comma in the textbox below.<br>”;
echo “<form method=’post’ action=’109_inclass.php’><input type=’text’ name=’trans’ /><button type=’submit’ /></form>”;
?>
</body>
</html>