Why a full stop, “.” and not a plus symbol, “+”, for string concatenation in PHP?

前端 未结 12 1626
暖寄归人
暖寄归人 2020-12-09 01:54

Why did the designers of PHP decide to use a full stop / period / \".\" as the string concatenation operator rather than the more usual plus symbol \"+\" ?

Is there

12条回答
  •  生来不讨喜
    2020-12-09 02:13

    I guess it is so you can concatenate numbers with strings?

    $i=100;
    $str="hello";
    $str2 = $str.$i
    

    Since you don't declare variable types, with a + it could give a result of 100 instead of "hello100."

提交回复
热议问题