That is, if you assign a string value to the variable var, var becomes a string. If you assign an integer value to var, it becomes an integer.
Type casting in PHP is very much like in C: the variable to be converted is preceded by the target type enclosed in parentheses.
Copy code The code is as follows:
$foo = 10;
echo "Convert Before: $foo=".$foo; //Output an integer
echo "
" //Output: $foo=10
echo "
";
$foo = (boolean) $foo; //Forced to boolean
echo "After conversion: $foo=".$foo; //Output: $foo=1
?>
The allowed casts are:
(int), (integer) - converted to integer type
(bool), (boolean) - converted to Boolean type
(float), ( double), (real) - Convert to floating point type
(string) - Convert to string
(array) - Convert to array
(object) - Convert to object
http://www.bkjia.com/PHPjc/320753.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320753.htmlTechArticleIn other words, if a string value is assigned to the variable var, var becomes a string. If you assign an integer value to var, it becomes an integer. Type coercion in PHP...