Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The output of echo 1, 2, 3, 4, 5 "is 6.

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

In PHP, how numeric characters and numbers participate in operations is determined in specific cases, for example: echo "3+4+5"; result: 3+4+5. Because it's treated like a string. When echo 1+2+"3+4+5", it is treated as an expression. This involves the calculation of different data types in PHP. When data of different data types are involved in the data, php will perform data conversion to ensure that the expression runs successfully as much as possible. The operator before "3+4+5" is +, so php will treat "3+4+5" as a numeric type. At this time, it will implicitly perform data type conversion to convert this string to a numeric value. The rule of php string conversion to integer is to extract as many numbers as possible from the front of the string, and discard the non-numeric parts after it. "3+4+5" is a character string. When entering numerical calculation, the character string will be rigidly converted into a numerical value. Generally, the value of the first character string will be taken. If it is a numerical character string, it will be a complete number. Therefore,"3+4+5" converts to a numerical value and the result is 3, so the result of the whole expression is: 1+2+3 =

6。

The output is 33+4+5.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report