Data type conversion in section 2 of PHP. In the following cases, the variable is considered NULL: The value is NULL. Not assigned. Unset (). The NULL type has only one value, that is, the case-insensitive keyword NULL (
In the following cases, the variable is considered to beNULL:
-
AssignedNULL.
-
Not assigned.
-
QuiltUnset ().
NULLThe type has only one value, which is a case-insensitive keyword.NULL(You can write NULL or null ).
Convert a variableNullType will delete the variable and unset its value.
Type conversion
PHP does not need (or does not support) explicit type definitions in variable definitions. variable types are determined by the context in which the variable is used. That is to say, if a string value is assigned to the variablevar,varIt becomes a string. If another integer value is assignedvarThen 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 the operands are treated as floating-point numbers, and the result is also a floating-point number. Otherwise, the operand is interpreted as an integer and the result is also an integer. Note that this does not change the type of these operands. it only changes how these operands are evaluated and the type of the expressions.
The forced type conversion in PHP is very similar to that in C: add the target type enclosed in parentheses before the variable to be converted.
- (Int), (integer)-to convertInteger)
- (Bool), (boolean)-convertBoolean)
- (Float), (double), (real)-convertFloat)
- (String)-convertString)
- (Binary)-convert to binaryString)(PHP 6)
- (Array)-convertArray)
- (Object)-convertObject)
- (Unset)-convertNULL(PHP 5)
(Binary) the prefix 'B' is added before the result, and PHP 5.2.1 is added.
Required NULL: The value is NULL. Not assigned. Unset (). The NULL type has only one value, that is, the case-insensitive keyword NULL (...