Four types of scalar:
- Boolean (Boolean)
- integer (integer type)
- float (floating-point, also called double)
- String (String)
Two kinds of composite types:
- Array (arrays)
- Object (objects)
Finally, there are two special types:
- Resource (resources)
- null (NULL)
To ensure the readability of the Code, this manual also describes some pseudo-types:
and the pseudo-variable $ ....
You might also read some references to the double-precision type. In fact double and float are the same, because of some historical reasons, both names exist at the same time.
The type of the variable is usually not set by the programmer, but rather is determined by the context in which PHP is used according to the variable.
Note: If you want to see the value and type of an expression, use var_dump ().
If you just want an easy-to-read type of expression for debugging, use GetType (). To view a type, do not use GetType (), and use the is_type function. Here are some examples:
Copy the Code code as follows:
$a _bool = TRUE; A Boolean
$a _str = "Foo"; A string
$a _str2 = ' foo '; A string
$an _int = 12; An integer
Echo GetType ($a _bool); Prints Out:boolean
Echo GetType ($a _str); Prints out:string
If This is a integer, increment it by four
if (Is_int ($an _int)) {
$an _int + = 4;
}
If $bool is a string, print it out
(Does not print out anything)
if (is_string ($a _bool)) {
echo "String: $a _bool";
}
?>
If you want to cast a variable to a type, you can use a cast or settype () function on it.
Note that the variable will behave differently depending on its current type. See type tricks for more information. In addition, you can refer to the PHP type comparison table to see different types of comparisons between the examples.
The above describes the JavaScript data type PHP Eight basic data type summary, including the JavaScript data type content, I hope to be interested in PHP tutorial friends helpful.