Which is better on performance: double quoted strings with variables or single quoted strings with concatenations?

前端 未结 7 2000
暗喜
暗喜 2020-12-11 07:17

I know that using single quotes around a string in PHP is faster than using the double quotes because PHP doesn\'t need to check for variable presence in the single quoted s

7条回答
  •  无人及你
    2020-12-11 07:50

    I wholeheartedly agree with Jonathan Sampson on this issue, but there's a solution which I believe is faster than the ones you posted. Using multiple arguments with echo:

    echo 'foo bar', $baz;
    

    This only applies when using the echo statement, in any other context concatenation is probably better, but I strive for readability in this so I use interpolation whenever possible.

提交回复
热议问题