This article mainly introduces the PHP data type conversion, the need for friends can refer to the
PHP does not need (or does not support) explicit type definitions in the variable definition, and the variable type is determined by the context in which the variable is used. In other words, if you assign a string value to a variable var,var, it becomes a string. If you assign an integer value to Var, it becomes an integer. An example of the automatic type conversion of PHP is the plus sign "+". If any operand is a floating-point number, all operands are treated as floating-point numbers, and the result is floating-point numbers. Otherwise the operand is interpreted as an integer and the result is a whole number. Note that this does not change the type of the operands themselves; it only changes how the operands are evaluated and the type of expression itself. Type casts allowed casts are: (int), (integer)-Converted to integer (integer) • (bool), (Boolean)-to Boolean (Boolean) • (float), (double), (real)-Convert to float (float) • (string)-Convert to String (string) • (binary)-Convert to binary string (string) (PHP 6) • (array)-Convert to Array (arr AY) • (object)-Convert to Object (object) • (unset)-Conversion to NULL (PHP 5) (binary) conversion will precede the result with prefix ' B ', PHP 5.2.1 new. Note allow spaces and tabs in parentheses convert string literals and variables to binary strings (string): code is as follows: <?php $binary = (binary) $ String $binary = B "binary string";?> If you want to change the type of a variable, see Settype (); settype-Set Variable type BOOL Settype (mixed $var, string $type) sets the type of the variable var. The possible values for type are: "boolean" (or "bool", from PHP 4.2.0) "integer" (or "int", from PHP 4.2.0) "FLoat "(Available only after PHP 4.2.0," Double "used in older versions is now deactivated) " string " " array " " Object " " null "(from PHP 4.2 .0) returns TRUE when it succeeds, or returns false. intval (), Floatval (), Strval () when it fails, and the three functions can also be converted