The result of the echo 1+2+ "3+4+5" Output is 6

Source: Internet
Author: User
Tags first string

In the PHP language, for digital characters and numbers how to participate in the operation, in specific cases will be determined, for example: echo "3+4+5"; Results: 3+4+5. Because it is treated as a string. When echo1+2+ "3+4+5", it is treated as an expression. This involves the problem of different data type operations in PHP. Data of different data types when participating in data, PHP will convert data to try to ensure that the expression successfully run, in the "3+4+5" before the operator is +, then, PHP will "3+4+5" as a numeric type, when the data type is implicitly converted, the string is converted to a numeric value, The rule for a PHP string to an integer is to extract as many numbers as possible from the front of the string, followed by a non-numeric part being discarded. "3+4+5" is a string, enter the numerical calculation, will be hard to convert the string to a numeric value, usually take the first string, if it is a numeric string, it is a complete number. Therefore, the result of the conversion of "3+4+5" to a number is 3, so the result of the entire expression is: 1+2+3=

6.


<?php

Echo (1+2). " 3+4+5 ";

?>

The result of the output is 33+4+5




This article is from the "12145704" blog, please be sure to keep this source http://12155704.blog.51cto.com/12145704/1867829

The result of the echo 1+2+ "3+4+5" Output is 6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.