php string number concatenation messed up

前端 未结 5 1337
灰色年华
灰色年华 2020-12-07 01:13

I got some php code here:

 

which outputs 234,

but when I add a number 11 before \"

5条回答
  •  粉色の甜心
    2020-12-07 01:58

    That's strange...

    But

    
    

    OR

    
    

    fixing issue.


    UPDv1:

    Finally managed to get proper answer:

    'hello' = 0 (contains no leading digits, so PHP assumes it is zero).

    So 'hello' . 1 + 2 simplifies to 'hello1' + 2 is 2, because no leading digits in 'hello1' is zero too.


    '11hello ' = 11 (contains leading digits, so PHP assumes it is eleven).

    So '11hello ' . 1 + 2 simplifies to '11hello 1' + 2 as 11 + 2 is 13.


    UPDv2:

    http://www.php.net/manual/en/language.types.string.php

    The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent. The exponent is an 'e' or 'E' followed by one or more digits.

提交回复
热议问题