Chapter 1 Test 2 - Code

Recap 1.9-1.12

Chapter 1 Main




<?php

require_once 'chapter1functions.php';
require_once "../mainfunctions.php";

printHead("1","Chapter 1 Test 2", "Recap 1.9-1.12");


//associative array
$kimbraArray=array("Kimbra1"=>"Lightyears", "Kimbra2"=>"Human",
"Kimbra3"=>"Past Love", "Kimbra4"=>"Right Direction", 
"Kimbra5"=>"Everybody Knows", "Kimbra6"=>"The Good War", 
"Kimbra7"=>"Top of the World", "Kimbra8"=>"Real Life",
"Kimbra9"=>"Recovery", "Kimbra10"=>"Like They Do on the TV",
"The Beatles"=>"The White Album");


echo'<h2>Artists and Albums</h2>';
foreach($kimbraArray as $artist=>$album){
echo $artist.": ".$album."<br>";
}
echo "<br>";


$download = "true";

if($download=="true"){$price="9.99";}
echo'<h2>Cost by Quantity- Downloads</h2>';
$quantity=1;//counter initialized/set to 1
while ($quantity < 6){ //loop length stated 
$price = round(priceCalc($price,$quantity),2);
//priceCalc function will multiply price by number of units
echo "$quantity for \$$price<br>"; //output variable contents
$quantity = $quantity + 1;//quantitiy increments from here
$price="9.99";//reset price each iteration of loop
}
echo "<br>";


$download = "false";

if($download=="false"){$price="12.99"; $total=$price; $shipping = "2.99";}
echo'<h2>Cost by Quantity- CDs</h2>';
for($quantity=1; $quantity < 6; $quantity++){
// ^ counter set to 1 + loop length stated + 
//quantity increments from here ^
$total= $shipping + round(priceCalc($total,$quantity),2);
//no discount on shipping ^
echo "$quantity for \$$total<br>"; //output variable contents
$total="12.99";//reset price each iteration of loop
}
echo "<br>";


printFootWithCodeExample("1.12test2code.php");

?>





BACK