-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug-sept-1.php
73 lines (59 loc) · 1.94 KB
/
debug-sept-1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
// -----------------------------------------------------------------------------
$pizza = [
'toppings' => ['pepperoni', 'green peppers', 'onions'],
'crust' => 'stuffed',
'delivery' => true,
];
// output the type of crust for the pizza
echo 'The type of crust for the first pizza: ' . PHP_EOL;
echo $pizza['crust'] . PHP_EOL;
// -----------------------------------------------------------------------------
$orders = [
[
'toppings' => ['pepperoni', 'green peppers', 'onions'],
'crust' => 'stuffed',
'delivery' => true,
'price' => 1295,
],
[
'toppings' => ['onion', 'salami'],
'crust' => 'pretzel',
'delivery' => false,
'price' => 1195,
],
[
'toppings' => ['pineapple', 'ham'],
'crust' => 'regular',
'delivery' => true,
'special instructions' => 'extra crispy crust',
'price' => 995,
]
];
// output all the different crust types
foreach ($orders as $order) {
echo $order['crust'] . PHP_EOL;
}
// output information about all the orders for delivery
foreach ($orders as $index => $order) {
// if the order is not for delivery skip it
if (! $order['delivery']) {
continue;
}
// human friendly order number
$orderNumber = $index + 1;
// turn our price in cents into a price in dollars and add a '$'
$formattedPrice = '$' . (float) $order['price'] / 100;
echo "---------------- Order # $orderNumber --------------" . PHP_EOL;
// display all the toppings
echo 'Toppings:' . PHP_EOL;
foreach ($order['toppings'] as $topping) {
echo " - $topping" . PHP_EOL;
}
echo "Crust: {$order['crust']}" . PHP_EOL;
// if the order has special instructions display them
if (isset($order['special instructions'])) {
echo "Special Prep: {$order['special instructions']}" . PHP_EOL;
}
echo "Total: $formattedPrice" . PHP_EOL;
}