Home >Backend Development >PHP Problem >How to force conversion of data types in php
How to force conversion of data types in php: Add the target type enclosed in parentheses before the variable to be converted to complete the forced type conversion, such as: [(int), (integer)] converted to Integer type; [(string)] is converted into a string.
In PHP, the forced type conversion can be completed by adding the target type enclosed in parentheses before the variable to be converted.
(Recommended tutorial: php graphic tutorial)
(int),(integer) Convert to integer type
(bool),(boolean) Convert to Boolean type
(float),(double),(real) Convert to floating point type
(string) Convert to string
(array) Convert to array
(object) Convert to object
(Video tutorial recommendation: php video tutorial)
Example:
<?php var_dump((bool) ""); // bool(false) var_dump((bool) 1); // bool(true) var_dump((bool) -2); // bool(true) var_dump((bool) "foo"); // bool(true) var_dump((bool) 2.3e5); // bool(true) var_dump((bool) array(12)); // bool(true) var_dump((bool) array()); // bool(false) var_dump((bool) "false"); // bool(true) ?>
The above is the detailed content of How to force conversion of data types in php. For more information, please follow other related articles on the PHP Chinese website!