When a string is evaluated as a number, the type and value of the result are determined according to the following rules.
If any one of the characters is included in ".", "E" or "E", the string is evaluated as a float. Otherwise, it is treated as an integer.
The value is determined by the first part of the string. Fei Fei, ASP Technology Park If the string starts with a valid numeric data, the number is used as its value, otherwise its value is 0 (0). Valid numeric data starts with an optional sign, followed by one or more digits (optionally including a decimal fraction) followed by an optional exponent. Fei Fei asp! Technology Park Index is an "E" or "E" followed by one or more numbers.
- < ? PHP
- $ Foo = 1 + "10.5";
$foo is float (11.5)
- $ Foo = 1 + " -1.3e3";
$foo is float (-1299)
- $ Foo = 1 + "bob-1.3e3";
$foo is integer (1)
- $ Foo = 1 + "BOB3";
$foo is integer (1)
- $ Foo = 1 + "Ten Small Pigs";
$foo is integer (11)
- $ Foo = 4 + "10.2 Little piggies";
$foo is float (14.2)
- $ Foo = "10.0 Pigs" + 1;
$foo is float (11)
- $ Foo = "10.0 Pigs" + 1.0;
$foo is float (11)
- ?>
If you want to test any of the PHP strings in this section into numeric examples, you can copy and paste the examples and add the following line to see what happens.
- < ? PHP
- echo "$ Foo = = $foo; Type is ".
GetType ($foo). "<br/>n";
- ?>
Do not expect to be able to encode a character when converting it to an integer (which may also be done in C). Use the Ord () and Chr () functions if you want to convert PHP strings to numeric values between character encodings and characters.
http://www.bkjia.com/PHPjc/446222.html www.bkjia.com true http://www.bkjia.com/PHPjc/446222.html techarticle When a string is evaluated as a number, the type and value of the result are determined according to the following rules. If you include., E, or e any one of the characters, the string is treated as a float ...