PHP supports eight primitive types (type), the following brother even PHP training
A small series to give you a list:.
Four types of scalar:
String (String)
Integer (integer type)
Float (floating point type, also double)
Boolean (Boolean)
Two kinds of composite types:
Array (arrays)
Object (Objects)
Two special types:
Resource (resources)
Null (empty)
View variable types
The GetType () function makes it easy to see the type of a variable:
<?php$var_bool = true;//a boolean$var_str = "foo"; a string$var_int = 12; Anintegerecho GetType ($var _bool); Output Booleanechogettype ($var _str); Output Stringecho GetType ($var _int);//Output integer?>
Tips
For historical reasons, if the data is float type, the GetType () function returns a double instead of float.
If you want to see the value and type of an expression, use the Var_dump () function.
Judging variable types
If you want to determine the next logical action by judging the variable type, do not use GetType () and use the Is_type series function:
<?php$var_int = 12;//If the $var _int is of type int, this is an addition if (Is_int ($var _int)) {$var _int = $var _int+4;} echo $var _int; Output 16?>
PHP Introductory Training tutorial PHP data type