PHP 变量插值与串联 [英] PHP variable interpolation vs concatenation

查看:30
本文介绍了PHP 变量插值与串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两种方法(性能、可读性等)有什么区别,你更喜欢什么?

What is the difference between the two following methods (performance, readability, etc.) and what do you prefer?

echo "Welcome {$name}s!"

对比

echo "Welcome " . $name . "!";

推荐答案

最适合您的工作...但如果你想提高速度,请使用这个:

Whatever works best for you works... But if you want to go for speed use this:

echo 'Welcome ', $name, '!';

单引号告诉 PHP 不需要解释,逗号告诉 PHP 只回显字符串,不需要连接.

The single quotes tell PHP that no interpretation is needed, and the comma tells PHP to just echo the string, no concatenation needed.

这篇关于PHP 变量插值与串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆