" //Output: $foo"/> " //Output: $foo">
Home > Article > Backend Development > Variable type PHP variable type coercion
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 "Before conversion: $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 above has introduced the forced conversion of variable types in PHP, including the content of variable types. I hope it will be helpful to friends who are interested in PHP tutorials.