<!DOCTYPE html>
<html>
<body>
<?php
// This is a single-line comment
# This is also a single-line comment
echo "<h1>My first PHP script!</h1><br>"; // new line at the end
$x = 5 + 5;
echo '$x = 5 + 5; $x value is: '.$x; // '.' connect strings
echo "<br>"; // New line
// array
$cars = array("Volvo","BMW","Toyota");
echo 'var_dump of: array("Volvo","BMW","Toyota") is: <br>';
var_dump($cars); // debug display
echo "<br><br>CLASS in PHP<br>";
// CLASS in PHP
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"); // construct
echo $myCar -> message();
echo "<br>";
$myCar = new Car("red", "Toyota");
echo $myCar -> message();
?>
</body>
</html>