PHP different variable Data types like the string & numeric types to more complex Data types like arrays and objects.
PHP supports data types like Integer, String, Booleans, Array, Object, Floating point number or Float, resource and NULL.
PHP supports the below data types :
A string can hold letters, special characters and numbers, and it can be as large as up to 2GB.
A string is a sequence of characters such as "Hello world!".
A string can be any text inside quotes . You can use single or double quotes :
<?php $x = "Hello world!"; $y = 'Hello world!'; echo $x; echo "<br>"; echo $y; ?>
Integer data type is used to store any non-decimal numeric value within the range -2,147,483,648 to 2,147,483,647.
An integer value can be negative or positive, but it cannot have a decimal.The PHP var_dump() function returns the data type and value:
<?php $x = 200; var_dump($x); ?>
Float data type is used to store any decimal numeric value.The PHP var_dump() function returns the data type and value:
<?php $x = 100.10; var_dump($x); ?>
Booleans have only two possible values either true or false.
$a = true; $b = false;
An array stores multiple values in one single variable.
<?php $colors = array("Red", "Green", "Blue"); var_dump($colors); ?>
PHP NULL data type is a special data type it means nothing. If it can only have one value and that is NULL.
If you create any variable and do not set/assign value to it, it will automatically have stored is NULL.
If Variables can also be empty by setting the value to NULL :
<?php $a = NULL; var_dump($a); echo "
"; $b = "Hello World!"; $b = NULL; var_dump($b); ?>
PHP resource is a special variable that holding a reference to an external resource.
PHP Resource variables typically hold special handlers to database connections and opened files.