Get the App
SLTechnology News&Howtos  ›  Network Security  › 

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

Shulou Source: shulou.com Published: 2022-06-01 04:14:11 10月06日 Update

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.

Tags: Characters strings numeric values data numbers results types expressions operations differences output success that is as much as possible case numeric integer time rules language Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB OPPO Reno Redmi vpn