-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.php
More file actions
47 lines (37 loc) · 1.32 KB
/
Copy pathcode.php
File metadata and controls
47 lines (37 loc) · 1.32 KB
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
<?php
class product {
//properties
var $size;
var $cost;
var $description;
var $name;
//constructor
function __construct($size,$cost,$description,$name) {
$this -> size = $size;
$this -> cost = $cost;
$this -> description = $description;
$this -> name = $name;
}
}
class products {
//googling how to set object variables...
var $productsList = array();
function addProduct($product) {
array_push($this -> productsList, $product);
}
public function ListProducts() {
$list = $this->productsList;
for($i=0;$i<count($list);$i++){
echo "Size: ".$list[$i]->size.", Cost: $".$list[$i]->cost.", Description: ".$list[$i]->description.", Name: ".$list[$i]->name."<br>";
}
}
}
$product1 = new product(7,14,"Red Shoes","Redz");
$product2 = new product(8,18,"Blue Shoes","Bluez");
$product3 = new product(9,23,"Green Shoes","Greenz");
$productList1 = new products();
$productList1 ->addProduct($product1);
$productList1 ->addProduct($product2);
$productList1 ->addProduct($product3);
$productList1 ->ListProducts();
?>