PHP's data type conversions are cast, and the PHP data types that are allowed to be converted are:
• (int), (integer): Convert to Reshape
• (float), (double), (real): Convert to floating-point
• (string): Convert to String
• (bool), (Boolean): Convert to Boolean type
• (array): Convert an array
• (object): Convert to Object
There are three ways to convert PHP data types:
• Precede the variable you want to convert with a target type enclosed in parentheses
• Use 3 specific types of conversion functions, intval (), Floatval (), Strval ()
• Use the common type conversion function Settype (mixed var,string type)
First conversion Mode: (int) (bool) (float) (string) (array) (object)
<? 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)
Second mode of conversion: Intval () floatval () Strval ()
<? PHP $str= "123.9abc"; $int=intval($str); // converted value: 123 $float=floatval($str// converted value: 123.9 $str= Strval ($float); // converted string: "123.9"
The third mode of conversion: Settype ();
<? PHP $num 4=12.8; $flg=settype($num 4, "int"); Var_dump ($flg); // output bool (true) Var_dump ($num 4// output int (?>)
PHP type Conversion