Home >Backend Development >PHP Tutorial >Summary of eight basic data types in PHP_PHP tutorial
Four scalar types:
Two compound types:
Finally there are two special types:
To ensure code readability, this manual also introduces some pseudo-types:
and pseudo variables $....
You may also read some references to the "double" type. In fact, double and float are the same, and for some historical reasons, these two names existed at the same time.
The type of a variable is usually not set by the programmer, rather it is determined by PHP at runtime based on the context in which the variable is used.
Note: If you want to check the value and type of an expression, use var_dump().
If you just want to get a human-readable representation of the type for debugging, use gettype(). To check a certain type, do not use gettype(), but use the is_type function. Here are some examples:
If you want to force a variable to a certain type, you can use cast or the settype() function.
Note that variables will exhibit different values in certain situations depending on their type at the time. See Type Tricks for more information. Additionally, you can refer to the PHP Type Comparison Chart for examples of how different types compare to each other.