adding php files for second exercise

This commit is contained in:
Dan Buch 2010-02-17 21:50:28 -05:00
parent 872ed812ca
commit a914a910d0
3 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,11 @@
<?php
// shipping.php contains our get_shipping_options($zipcode, $pounds) function.
// It returns an array mapping service name to price in US dollars.
require ('shipping.php');
$options = get_shipping_options($_REQUEST[zipcode], $_REQUEST[pounds]);
foreach ($options as $service => $price) {
$result[] = "$service: $price USD";
}
print implode("\n", $result);
?>

View File

@ -0,0 +1,12 @@
<?php
// Returns an array of made-up shipping options.
function get_shipping_options($zipcode, $pounds) {
$baseCost = round($zipcode / 10000) + ($pounds * 5);
$options = array( "Next Day" => $baseCost * 4,
"Two Day Air" => $baseCost * 2,
"Saver Ground" => $baseCost);
return $options;
}
?>

View File

@ -0,0 +1,15 @@
<?php
// shipping.php contains our get_shipping_options($zipcode, $pounds) function.
// It returns an array mapping service name to price in US dollars.
require('shipping.php');
$options = get_shipping_options($_REQUEST["zipcode"], $_REQUEST["pounds"]);
$results[] = "<options>";
foreach ($options as $service => $price) {
$results[] = "<option><service>$service</service><price>$price</price></option>";
}
$results[] = "</options>";
print implode("\n", $results);
?>