In PHP, a variable holds different values of various data types. Following data types are supported by PHP:
They are a non-decimal numbers and can be negative, zero and positive values. The range of integers is -2,147,483,648 to 2,147,483,647. Integers can be in three different formats: Hexadecimal (Base 16), Decimal (Base 10) and Octal (Base 8).
In the given below example, variables $KH_Number1 and $KH_Number2 are assigned an integer value. You can know the datatype of variable using var_dump function of PHP.
<?php $KH_Number1 = 3120; var_dump($KH_Number1); $KH_Number2 = 451 + 98421; var_dump($KH_Number2); ?>
They are sequences of the characters. String can be defined using single quote and double quote. Single quote will consider the string as it is, whereas, double quote can parse the variable and replace its value.
<?php $KH_Name = "John"; $KH_DisaplyName1 = 'My name $KH_Name is not displayed here'; $KH_DisaplyName2 = "My name is $KH_Name"; echo $KH_DisaplyName1 . "<br>"; // Output: My name $KH_Name is not displayed here echo $KH_DisaplyName2 ; // Output: My name is John ?>
They are numbers with decimal places like 461.45.
<?php $KH_Double = 945.12; var_dump ($KH_Double); ?>
They have likely two states either true or false. Booleans are frequently used in conditional testing with if statement.
<?php $KH_Knowphp = true; if ($KH_Knowphp) echo "I know PHP script"; else echo "I don't know PHP script"; ?>
It is a special data type which contains only one value: null. The variable of null data types means that variable is not assigned with any value. It is often used with isset() function.
<?php $KH_Name = null; if (!isset($KH_Name)) echo "Variable does not contain value"; else echo "Variable has the value of $KH_Name"; ?>