Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Convert Strings to Numbers
How To Convert Strings to Numbers? - PHP Script Tips - Understanding String Literals and Operations
✍: 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
2007-04-20, 4859👍, 0💬
Popular Posts:
What is the output of printf("%d")? 1. When we write printf("%d",x); this means compiler will print ...
What does static variable mean? There are 3 main uses for static variables: If you declare within a ...
Can you explain in brief how the ASP.NET authentication process works? ASP.NET does not run by itsel...
What is the main difference between a Vector and an ArrayList? Java Vector class is internally synch...
What will be printed as the result of the operation below: main() { char s1[]="Cisco"; char s2[]="sy...