type of variable php code example
Example 1: find type in php
gettype($u)
Example 2: getttype php
gettype ( mixed $var ) : string
gettype ("SALUT") => string
gettype (2) => integer
...etc ...
"bool"
"integer"
"double"
"array"
"object"
"resource"
"NULL"
"unknown type"
Example 3: php what type of variable is it
echo gettype($var1)."\n";
echo gettype($var2)."\n";
echo gettype($var3)."\n";
Example 4: 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 5: php define variable type
<?php
$foo = "5bar";
$bar = true;
settype($foo, "integer");
settype($bar, "string");
?>