forked from assembler-institute/php-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.php
More file actions
54 lines (46 loc) · 812 Bytes
/
types.php
File metadata and controls
54 lines (46 loc) · 812 Bytes
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
<?php
// type string
$a = "Hello world!";
var_dump($a);
echo '<br><br>';
// type integer
$b = 5985;
var_dump($b);
echo '<br><br>';
// type float
$c = 10.365;
var_dump($c);
echo '<br><br>';
// type boolean
$d = true;
var_dump($d);
echo '<br><br>';
// null
$e = null;
var_dump($e);
// type array
$cars = array("Volvo", "BMW", "Toyota");
var_dump($cars);
echo '<br><br>';
// type object (class)
class Car
{
public $color;
public $model;
public function __construct($color, $model)
{
$this->color = $color;
$this->model = $model;
}
public function message()
{
return "My car is a " . $this->color . " " . $this->model . "!";
}
}
$myCar = new Car("black", "Volvo");
echo $myCar->message();
echo "<br>";
$myCar = new Car("red", "Toyota");
echo $myCar->message();
echo '<br><br>';
?>