variables types php code example
Example 1: php data types
<?php
$x = "Hello world!";
echo $x;
$x = 5985;
var_dump($x);
$x = 10.365;
var_dump($x);
$x = true;
$y = false;
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
class Car {
function Car() {
$this->model = "VW";
}
}
$herbie = new Car();
echo $herbie->model;
$x = "Hello world!";
$x = null;
var_dump($x);
?>
Example 2: php define variable type
<?php
$foo = "5bar";
$bar = true;
settype($foo, "integer");
settype($bar, "string");
?>
Example 3: PHP Data Types
<?php
$x = "Hello world!";
$y = 'Hello world!';
echo $x;
echo "<br>";
echo $y;
?>