Variables and Data Types
Variables
<?php
$name = "Alice"; // This is a string.
$age = 25; // This is an integer.
$weight = 65.5; // This is a float.
$isStudent = true; // This is a boolean.
?>Data Types
<?php $string = "Hello, World!"; echo $string; // Outputs: Hello, World! ?><?php $integer = 42; echo $integer; // Outputs: 42 ?><?php $float = 3.14; echo $float; // Outputs: 3.14 ?><?php $boolean = true; echo $boolean; // Outputs: 1 (for TRUE) ?><?php $array = array("Alice", "Bob", "Charlie"); print_r($array); // Outputs: Array ( [0] => Alice [1] => Bob [2] => Charlie ) ?><?php class Car { function Car() { $this->model = "VW"; } } $herbie = new Car(); // create an object echo $herbie->model; // show object properties ?><?php $var = NULL; var_dump($var); // Outputs: NULL ?>
Last updated