PHP 5 Data Types
PHP 5 Data Types
String (String), Integer (Float), Boolean (Boolean), Array (Object), NULL (null value).
A string is a sequence of characters, like "Hello world!".
You can put any text in single and double quotes:
An integer is a number without decimals.
- Integers must have at least one number (0-9)
- Integers cannot contain commas or spaces
- Integers have no decimal point
- Integer can be positive or negative
- Integers can be specified in three formats: decimal, Hex (prefixed with 0x) or octal (prefixed with 0).
In the following examples we will test different numbers.
PHP var_dump () The function returns the data type and value of the variable:
Floating point numbers are numbers with decimal parts or exponential form.
In the following examples we will test different numbers. PHP var_dump () The function returns the data type and value of the variable:
Boolean can be TRUE or FALSE.
$ y = false;
Boolean is usually used for conditional judgment. You will learn more about conditional control in the following chapters.
Array can store multiple values in one variable.
An array was created in the following example, Then use PHP var_dump () The function returns the data type and value of the array:
You will learn more about arrays in the following chapters.
Object data types can also be used to store data.
In PHP, objects must be declared.
First, you must declare a class object using the class keyword. A class is a structure that can contain properties and methods.
Then we define the data type in the class and then use the data type in the instantiated class:
The PHP keyword this in the above example is a pointer to the current object instance, and does not point to any other objects or classes.
You will learn more about objects in the following chapters.
PHP NULL Value
A NULL value indicates that the variable has no value. NULL is a value whose data type is NULL.
A NULL value indicates whether a variable is null. The same can be used for the difference between data null and NULL values.
Variable data can be cleared by setting the variable value to NULL: