Search code examples
phpquotesstring-concatenation

PHP - "Sal's mall is $emo" vs "Sal's mall is ".$emo - string with quotes concatenation efficiency


In PHP, which is a better way to concatenate strings (with a single-quote) in terms of resources?

"Sal's mall is $emo."

Or:

"Sal's mall is ".$emo.'.'

Or:

'Sal\'s mall is '.$emo.'.'

Solution

  • 'Sal\'s mall is '.$emo.'.'
    

    The third way is more efficient (slightly). You can test it by yourself doing a loop:

    for ($i = 0; $i < 100000; $i++) {
        // enter code here 
    }