Home >Backend Development >PHP Tutorial >PHP data type automatic conversion
1: Overview---php is a weakly typed language, which can automatically convert data types according to changes in the running environment
1.1 Principles of conversion to Boolean types
The following values will be converted into Boolean types false:
A. Boolean type false;
B. Empty string ''
C. Positive number 0 or floating point number 0.0 or string '0' (excluding string '0.0')
D .Array without members----array()
E.null
Except for this, all other values are converted to true.
1.2 Principles of conversion to numerical type
A. If the string is a legal number If the string does not contain ./e/E and does not exceed the storage range of the integer type, it will be converted to an integer type; otherwise, it will be converted to a floating point type;
B. If the numeric string starts with an illegal character, then converted to 0;
C. Boolean true is converted to integer 1, false is converted to integer 0;
D. null is converted to 0
E. Floating point numbers are rounded down when converted to integers
1.3 Conversion The principle of converting into a string
A. The value is converted into a string, which is the value itself; String'';
D. Convert the array to Array
E. The resource will be converted to Resource id #number
The above introduces the automatic conversion of data types in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.