PHP does not require (or does not support) explicit type definition in variable definition; the variable type is determined based on the context in which the variable is used. decided. In 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.
An example of PHP's automatic type conversion is the plus sign " ". If any operand is a floating point number, all operands are treated as floating point numbers, and the result is also a floating point number. Otherwise the operands are interpreted as integers and the result is also an integer. Note that this does not change the types of the operands themselves; only how the operands are evaluated and the type of the expression itself is changed.
The allowed casts are:
(binary) conversion will prefix the result with 'b', new in PHP 5.2.1.
Note that spaces and tabs are allowed within brackets
Convert string literals and variables to binary string:
<?php $binary = (binary)$string; $binary = b"binary string"; ?>
If you want to change the type of a variable, see settype();
settype — Set the type of variable
bool settype ( mixed $var , string $type )Set the type of variable var to type.
Possible values fortype are:
Returns TRUE on success, or FALSE on failure.
intval(), floatval(), strval(), these three functions can also be converted