PHP Data type conversions
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:
? Add the target type enclosed in parentheses before the variable you want to convert
? Use 3 specific types of conversion functions, intval (), Floatval (), Strval ()
? Using the common type conversion function Settype (mixed var,string type)
First conversion Mode: (int) (bool) (float) (string) (array) (object)
1.<?php
2. $num 1=3.14;
3. $num 2= (int) $num 1;
4.var_dump ($num 1); Output float (3.14)
5.var_dump ($num 2); Output int (3)
6.?>
Second mode of conversion: Intval () floatval () Strval ()
1.<?php
2. $str = "123.9ABC";
3. $int =intval ($STR); Post-conversion value: 123
4. $float =floatval ($STR); Post-conversion value: 123.9
5. $str =strval ($float); Converted string: "123.9"
6.?>
The third mode of conversion: Settype ();
1.<?php
2. $num 4=12.8;
3. $flg =settype ($num 4, "int");
4.var_dump ($FLG); output bool (TRUE)
5.var_dump ($num 4); Output int (12)
6.?>
PHP Data type conversion (RPM)