Three ways to convert data types in PHP, data types three ways
PHP's data type conversions are cast, and the PHP data types that are allowed to be converted are:
1. (int), (integer): Convert to Reshape
2. (float), (double), (real): Convert to floating-point type
3. (string): Convert to String
4. (bool), (Boolean): Convert to Boolean type
5. (array): Convert an array
6. (object): Convert to Object
There are three ways to convert PHP data types:
1. Add the target type enclosed in parentheses before the variable you want to convert
2. Use 3 specific types of conversion functions, intval (), Floatval (), Strval ()
3. Using the common type conversion function Settype (mixed var,string type)
First conversion Mode: (int) (bool) (float) (string) (array) (object)
Copy the 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)
?>
Second mode of conversion: Intval () floatval () Strval ()
Copy the Code code as follows:
<?php
$str = "123.9ABC";
$int =intval ($STR); Post-conversion value: 123
$float =floatval ($STR); Post-conversion value: 123.9
$str =strval ($float); Converted string: "123.9"
?>
The third mode of conversion: Settype ();
Copy the 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)
?>
A journey begins with a journey. Change the future, starting from now. Changing the present is changing the future.
http://www.bkjia.com/PHPjc/978383.html www.bkjia.com true http://www.bkjia.com/PHPjc/978383.html techarticle PHP Data type conversion in three ways, data type three ways PHP data type conversion is cast, the allowable conversion of PHP data types are: 1. (int), (integer): Go ...