This article mainly to share with you PHP data type conversion and type detection, although the basic knowledge of PHP, but very useful, I hope to help everyone.
Implicit conversions (auto-conversion)
Convert to String type
True--' 1 '
False, null, and empty string
Convert to numeric type
Start with a valid value and take it to the end of the first illegal value;
Start with a non-legal value and convert to 0
Convert to Boolean type
0, 0.0, ', ', ' 0 ', NULL, array () is false;
String, Integer, floating-point number, ' 0.0 ', ' false ', ' true '.
Show transformations
Temporary conversion
1. (variable type) $ variable name
Grammar:
Integer: (int) $ variable name
Float type: (float) $ variable name
Character type: (string) $ variable name
Boolean type: (BOOL) $ variable Name
Null: (unset) $ variable name
Number: (array) $ variable name
Object: (object) $ variable name
2. System function implementation
Intval ($ variable name) returns the value of the variable converted to an integer
Floatval ($ variable name) returns the value of a variable converted to a floating-point type
Strval ($ variable name) returns the value of the variable converted to a string type
Oolval ($ variable name) returns the value of the variable converted to a Boolean type
Permanent conversion
Settype ($ variable name, ' type ') sets the type of the variable
Detecting variable types
Integer type Is_int ()
Floating-point is_float ()
String is_string ()
Boolean type Is_bool ()
Scalar type is_scalar ()
Empty Is_null ()
Array Is_array ()
Object Is_object ()
Resource Is_resource ()
Numeric Is_numeric () in numeric or string form
Implicit conversions (auto-conversion)
Convert to String type
True--' 1 '
False, null, and empty string
Convert to numeric type
Start with a valid value and take it to the end of the first illegal value;
Start with a non-legal value and convert to 0
Convert to Boolean type
0, 0.0, ', ', ' 0 ', NULL, array () is false;
String, Integer, floating-point number, ' 0.0 ', ' false ', ' true '.
Show transformations
Temporary conversion
1. (variable type) $ variable name
Grammar:
Integer: (int) $ variable name
Float type: (float) $ variable name
Character type: (string) $ variable name
Boolean type: (BOOL) $ variable Name
Null: (unset) $ variable name
Number: (array) $ variable name
Object: (object) $ variable name
2. System function implementation
Intval ($ variable name) returns the value of the variable converted to an integer
Floatval ($ variable name) returns the value of a variable converted to a floating-point type
Strval ($ variable name) returns the value of the variable converted to a string type
Oolval ($ variable name) returns the value of the variable converted to a Boolean type
Permanent conversion
Settype ($ variable name, ' type ') sets the type of the variable
Detecting variable types
Integer type Is_int ()
Floating-point is_float ()
String is_string ()
Boolean type Is_bool ()
Scalar type is_scalar ()
Empty Is_null ()
Array Is_array ()
Object Is_object ()
Resource Is_resource ()
Numeric Is_numeric () in numeric or string form