This article mainly introduces the conversion and detection of PHP data types. It has certain reference value. Now I share it with everyone. Friends in need can refer to it
1. Data types Conversion
Although PHP is a weakly typed language, data can be converted just like C language. Just add the type name enclosed in parentheses before the variable.
Convert to Boolean type: such as (boolean)
##str##flo
##str
Convert to floating point type: For example, (float)$strbool settype(mixed var,string type)
Note: The parameter var is the specified variable; the parameter type is the specified data type. The parameter type has 7 optional values, namely boolean, float, .integer, array, null, object and string. If the conversion is successful, the settype() function returns true, otherwise it returns false.When the string is converted to an integer or floating point type, if the string starts with a number, the number part will be converted to an integer first. type, and then the following string will be removed; if the number contains a decimal point, the number before the decimal point will be retrieved.
2. Data type detection
is bool Check whether the variable is a Boolean type: such as is bool(true), is_bool(false)
PHP data type conversion ( Character to number, number to character)
The above is the detailed content of PHP data type conversion and detection. For more information, please follow other related articles on the PHP Chinese website!