PHP data type
PHP data type:
Variables can hold different types of data and different tasks can be performed through different types of data.
PHP supports the following data types
Boolean - true or false
String - Character set
Float - Decimal numbers
Array - Variable for storing multiple values
Object - User-defined data type
NULL - Empty variable
Resource - Identifies or refers to external functions or resources
Boolean provides only two values. E.g. true or false.
Boolean data is often used to verify conditions. Condition verification is discussed in the next chapter.
The integer is any integer between -2,147,483,648 and 2,147,483,647.
Integer must have at least one digit.
Integer cannot contain decimal numbers.
Integer can be positive or negative.
Integer can be identified by three formats:
hexadecimal (18 based - starts with 0x)
octal (৮-based - starts with 0)
In the following example $year is integer and PHP var_dump () function is used to know its data type and value:
A string is a sequence of letters. Such as- "Hello Bangladesh!".
Any text used in quotation marks is a string. Strings can be placed in single or double quotations
Float is a decimal number. It can be written in decimal or exponential (ex) form.
In the following example, that $number is float and the PHP var_dump() function is used to determine its data type and value:
Array is a variable that allows you to store more than one value at a time.
In the following example $satt is an array variable and the PHP var_dump() function is used to know its data type and value:
The next chapter discusses Array in detail.
Object is a data type that contains not only data, but also information on how to process that data.
Object data type is different from all other data types. You must use the new keyword to declare an object in PHP.
For Object Data, we must first declare the class. You have to use the class keyword to announce the class. A class is a type of template or structure that can contain the object's properties and methods:
The next chapter discusses Object in detail.
Null is a special type of data type that has only one value. E.g.- NULL.
Variables in which no value is assigned have data type NULL.
Note: If a variable is declared without a value, its value is automatically NULL or empty.
Variable values can be left blank by assigning NULL.
PHP is a special type of data type. Resource is not an actual data type. It actually stores the reference of the function or external PHP resource.
A common example of a resource data type is database calling.