Tools, FAQ, Tutorials:
Converting Numbers to Strings in PHP
How To Convert Numbers to Strings?
✍: FYIcenter.com
In a string context, PHP will automatically convert any numeric value to a string. Here is a PHP script examples:
<?php print(-1.3e3); print("\n"); print(strlen(-1.3e3)); print("\n"); print("Price = $" . 99.99 . "\n"); print(1 . " + " . 2 . " = " . 1+2 . "\n"); print(1 . " + " . 2 . " = " . (1+2) . "\n"); print(1 . " + " . 2 . " = 3\n"); print("\n"); ?>
This script will print:
-1300 5 Price = $99.99 3 1 + 2 = 3 1 + 2 = 3
The print() function requires a string, so numeric value -1.3e3 is automatically converted to a string "-1300". The concatenation operator (.) also requires a string, so numeric value 99.99 is automatically converted to a string "99.99". Expression (1 . " + " . 2 . " = " . 1+2 . "\n") is a little bit interesting. The result is "3\n" because concatenation operations and addition operation are carried out from left to right. So when the addition operation is reached, we have "1 + 2 = 1"+2, which will cause the string to be converted to a value 1.
⇒ Converting Strings to Numbers in PHP
⇐ Comparing Two Strings in PHP
2016-10-13, 1393👍, 0💬
Popular Posts:
Where to find tutorials on OpenID? Here is a large collection of tutorials to answer many frequently...
How to use "xml-to-json" Azure API Policy Statement? The "xml-to-json" Policy Statement allows you t...
What Is HTML? HTML (HyperText Markup Language) is the standard markup language for creating Web page...
What is EPUB 2.0 Metadata "dc:creator" and "dc:contributor" elements? EPUB 2.0 Metadata "dc:creator"...
How to use "link" command tool to link objet files? If you have object files previously compiled by ...