Php Data type conversion, php data type. Php Data Type Conversion. php Data types PHP does not need (or do not support) explicit type definitions in variable definitions. variable types are determined by the context in which the variable is used. That is, php Data type conversion, and php Data 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.
Type forced conversion
The following mandatory conversions are allowed:
- (Int), (integer)-convert to integer (integer)
- (Bool), (boolean)-convert to boolean (boolean)
- (Float), (double), (real)-convert to float)
- (String)-convert to string (string)
- (Binary)-convert to a binary string (string) (PHP 6)
- (Array)-convert to an array (array)
- (Object)-convert to object)
- (Unset)-convert to NULL (PHP 5)
(Binary) the prefix 'B' is added before the result, and PHP 5.2.1 is added.
Note that empty spaces and tabs are allowed in parentheses.
Convert string text and variables to a binary string ):
To change the type of a variable, see settype ();
Settype-set the variable type
Bool
Settype(Mixed $ Var, String $ Type)
Change the variableVarToType.
TypeThe possible values are:
- "Boolean" (or "bool", starting from PHP 4.2.0)
- "Integer" (or "int", starting from PHP 4.2.0)
- "Float" (only available after PHP 4.2.0, and "double" used in earlier versions is disabled now)
- "String"
- "Array"
- "Object"
- "Null" (from PHP 4.2.0)
Return if successfulTRUE, Or return when the failure occurs.FALSE.
Intval (), floatval (), strval (), these three functions can also be converted
Pluphp 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...