Data types in PHP, like any other programming language reflects which type of data is stored in variable. Since, as discussed earlier, PHP is loosely typed programming language, so there is no need to define the data-type when declaring a variable. The values passed within a variable automatically makes it of that type.
PHP supports total eight different type of data-types :
PHP Integer (Data Types in PHP)
Integer variables in PHP can any non-decimal number between -2,147,483,648 to 2,147,483,648. Integer variables in PHP can share following features –
– Integers in PHP can be negative or positive
– Integers in PHP must not have a decimal value.
– Integers in PHP must have atleast one digit.
– Integers in PHP can be specified in decimal, hexadecimal, octal, or binary numbers.
PHP String
String variables in PHP is a collection of characters and spaces, string values in PHP are always enclosed in quotes (either single or double quotes). Anything inside a quotes is a string.
PHP Float
Decimals or fractional values are considered as float variables in PHP. These values must be specified without quotes.
– Floating values can be either positive or negative.
– Decimal must be used to while storing floating type values.
– Exponential form can also be used in floating point values.
PHP Boolean
Boolean variables in PHP represents two states either true(1) or false(0). You can simply write true or false to declare a variable as Boolean type.
Arrays in PHP
Arrays in PHP is a variable that can hold multiple values at a time with similar data-type for example a set of states in India can be stored within an array in PHP.
PHP NULL Value
It is a special data type in PHP which can hold only one value i.e. NULL.
If a variable is created without assigning a value to it, it will aromatically store NULL.