When the first expression is a string, the type of the variable will depend on the second expression. : Casting « Data Type « PHP






When the first expression is a string, the type of the variable will depend on the second expression.

 
<?
$foo = 1 + "10.5"; // $foo is double (11.5)
$foo = 1 + "-1.3e3"; // $foo is double (-1299)
$foo = 1 + "bob-1.3e3"; // $foo is integer (1)
$foo = 1 + "bob3"; // $foo is integer (1)
$foo = 1 + "10 Small Pigs"; // $foo is integer (11)
$foo = 1 + "10 Little Piggies"; // $foo is integer (11)
$foo = "10.0 pigs " + 1; // $foo is integer (11)
$foo = "10.0 pigs " + 1.0; // $foo is double (11)
?>
  
  








Related examples in the same category

1.Casting a variable
2.Casting the return value
3.Change the data type
4.Changing Type by Casting
5.Converting to in parentheses before our variable name
6.Maintaining the integrity of the data and outputting the end result.
7.Force to change the data type by adding (int), (integer), (float), (double), or (real) in front of the variable
8.convert to float
9.Typecasting
10.Casting a Variable
11.Type conversion: Approach 2
12.Type conversion: Approach 1
13.Type conversion: approach 3
14.Type conversions
15.Convert String to Date