我正在努力优化我的 PHP 代码,并发现您可以通过这些方式加快回显速度 - 确切地说,您可以将 echo "The name of the user is $name" . "."; 替换为:

  • echo 'The name of the user is '.$name.'.';
  • echo "The name of the user is", $name, ".";
  • echo sprintf("The name of the user is %s", $name);

  • 哪个最快?如果可能的话,我不仅希望看到基准测试,还希望看到一些技术说明。

    最佳答案

    首先,这是微优化,您可能最好为更快的服务器支付费用并开发更多产品,然后再花费数小时进行微优化。然而,根据 http://micro-optimization.com/ 这里是结果:





    关于php - 串联、多个参数还是 sprintf?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17012284/

    10-12 12:25
    查看更多