Performance of variable expansion vs. sprintf in PHP

后端 未结 6 1183

Regarding performance, is there any difference between doing:

$message = \"The request $request has $n errors\";

and

$messa         


        
6条回答
  •  春和景丽
    2020-12-06 16:57

    For Injecting Multiple String variables into a String, the First one will be faster.

    $message = "The request $request has $n errors";
    

    And For a single injection, dot(.) concatenation will be faster.

    $message = 'The request '.$request.' has 0 errors';
    

    Do the iteration with a billion loop and find the difference.

    For eg :

    
    

提交回复
热议问题