Tools, FAQ, Tutorials:
Converting Strings to Numbers in PHP
How To Convert Strings to Numbers?
✍: FYIcenter.com
In a numeric context, PHP will automatically convert any string to a numeric value. Strings will be converted into two types of numeric values, double floating number and integer, based on the following rules:
Here is a PHP script example of converting some examples:
<?php $foo = 1 + "10.5"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 1 + "-1.3e3"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 1 + "bob-1.3e3"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 1 + "bob3"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 1 + "10 Small Pigs"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 4 + "10.2 Little Piggies"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = "10.0 pigs " + 1; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = "10.0 pigs " + 1.0; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; ?>
This script will print:
$foo=11.5; type is double $foo=-1299; type is double $foo=1; type is integer $foo=1; type is integer $foo=11; type is integer $foo=14.2; type is double $foo=11; type is double $foo=11; type is double
⇒ PHP Built-in Functions for Strings
⇐ Converting Numbers to Strings in PHP
2016-10-13, 1592🔥, 0💬
Popular Posts:
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
How to use "xsl-transform" Azure API Policy Statement? The "xsl-transform" Policy Statement allows y...
How to extend json.JSONEncoder class? I want to encode other Python data types to JSON. If you encod...
How To Get the Minimum or Maximum Value of an Array in PHP? If you want to get the minimum or maximu...