PHP data type conversions are cast, and PHP data types that allow conversion are:
1. (int), (integer): Convert to Plastic
2. (float), (double), (real): Convert to floating point type
3. (string): Convert to String
4. (bool), (Boolean): Convert to Boolean type
5. (array): Converting an array of
6. (object): Convert to Object
There are three ways to convert PHP data types:
1. Precede the variable to be converted with a target type enclosed in parentheses
2. Use 3 specific types of conversion functions, intval (), Floatval (), Strval ()
3. Use common type Conversion functions Settype (mixed var,string type)
First mode of conversion: (int) (bool) (float) (string) (array) (object)
Copy Code code as follows:
<?php
$num 1=3.14;
$num 2= (int) $num 1;
Var_dump ($num 1); Output float (3.14)
Var_dump ($num 2); Output int (3)
?>
The second mode of conversion: Intval () floatval () Strval ()
Copy Code code as follows:
<?php
$str = "123.9ABC";
$int =intval ($STR); Value after conversion: 123
$float =floatval ($STR); Value after conversion: 123.9
$str =strval ($float); After conversion string: "123.9"
?>
The third mode of conversion: Settype ();
Copy Code code as follows:
<?php
$num 4=12.8;
$FLG =settype ($num 4, "int");
Var_dump ($FLG); output bool (TRUE)
Var_dump ($num 4); Output int (12)
?>
The journey of the journey begins with a. Change the future, start from now. To change the present is to change the future.