Home >Backend Development >PHP Tutorial >Automatic data type conversion in php, data type conversion in php_PHP tutorial
1: Overview---php is a weakly typed language, which can change according to changes in the running environment Automatically convert data types
1.1 Principles of conversion to Boolean type
The following values will be converted to false in the Boolean type:
A. false of Boolean type;
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 Principle of conversion into numerical value
A. If the string is a legal numeric string, does not contain ./e/E, and does not exceed the storage range of integer, it will be converted to integer type; otherwise, it will be converted to floating point type;
B. If the numeric string starts with an illegal character, it is converted to 0;
C. Boolean true is converted into an integer 1, false is converted into an integer 0;
D.null is converted to 0
E. Round down when converting floating point numbers into integers
1.3 Principles of converting into string
A. The value is converted into a string, which is the value itself;
B. Boolean true is converted into a string '1'; false is converted into a string '';
C.null is converted into an empty string'';
D. Convert array to Array
E. The resource will be converted into Resource id #number