In programming language variables are required to store information of data.
Variables have different data types.
PHP have following data types give below.
A string is any sequence of characters or text inside single or double quotes.
Here is the code of string data types.
Code | |||||||
---|---|---|---|---|---|---|---|
<?php // PHP String $s="Hello PHP String"; $s1='Hello PHP String'; echo $s." |
Type Url - https://localhost/php/string.php
An integer data type is any positive or negative non-decimal number between -2,147,483,648 and 2,147,483,647.
An integers can be specified in three formats given below.
Here is the code of integer data types.
Code | |||||||
---|---|---|---|---|---|---|---|
<?php // PHP Integer $a = 3636; //Positive number var_dump($a); echo " |
Type Url - https://localhost/php/integer.php
A float number is a number with a decimal point.
Code | |||||||
---|---|---|---|---|---|---|---|
<?php // PHP Floating $a = 36.36; var_dump($a); ?> |
Type Url - https://localhost/php/floating.php
A boolean data type can take on of the possible two values: true or false.
Code | |||||||
---|---|---|---|---|---|---|---|
<?php // PHP Boolean $flag = true; var_dump($flag); ?> |
Type Url - https://localhost/php/boolean.php
An array is used when multiple values have to be stored for a single variable.
Code | |||||||
---|---|---|---|---|---|---|---|
<?php // PHP Array $student = array("John","Doe","Tom"); var_dump($student); ?> |
Type Url - https://localhost/php/array.php
A variable of data type NULL has no value assigned to it.
When $a a variable is created with no value stored in it, it is automatically assigned a null value.
If one wants to empty a variable, then its value can be set to null.
Code | |||||||
---|---|---|---|---|---|---|---|
<?php // PHP NULL $a = 120 // Integer value $a = null; var_dump($a); echo " |
Type Url - https://localhost/php/null.php
A resource is not an actual data type. It is a reference to a functions, objects or resources external to it.
For e.g. A resource data type in a php program might refer to a field in a database.