1. Coercion of type conversions
SetType (' variable ', ' value ')
Value: Can be any of the 8 big data types
Variables: (8 Big data types) variables that need to be converted
$var="123abc"; SetType ($var'int') ); Var_dump ($var);
Execution result: int 123
$var="123abc"; $New= (int) $var; var_ Dump ($new);
Execution Result: int 123
2. Automatic type conversion
(most used, variables are automatically converted according to the environment)
$str ='123abc'; $int='521'; $result = $str +$int//+ number requires a numeric var_dump ($result) on both sides;
Execution Result: int 644
(Functions related to data types)
$arr=array(1,2,3,4,5); $a=getType($arr); Var_dump ($a);
Execution Result:
string
' array ' (length=5)
(Each data type will have a function to determine if this is the type)
Is_int ();
Is_float ();
Is_string ();
Is_array ();
Is_numeric (); Used to determine whether a numeric type, integral type, and float type are numeric types
$num=123; $flo=3.1415926; Var_dump (is_numeric($num)); Echo "<br/>"; Var_dump (is_numeric($flo));
Execution Result:
Boolean
True
Boolean
True
Conversion of PHP Data types