这更多是一个最佳实践的问题。
我想知道在双引号字符串中使用大括号来表示变量是否是一种好的做法。
例如:
<?php
$Variable = 'a variable';
$SingleQuotedString = 'Single quoted string with ' . $Variable;
// Single quoted string with a variable
$DoubleQuotedString = "Double quoted string with $Variable";
// Double quoted string with a variable
$DoubleQuotedStringWithBrackets = "Double quoted string with {$Variable} in brackets.";
// Double quoted string with a variable in brackets.
?>
它不会改变简单测试中的输出或代码,显然是可行的。我很困惑,因为没有多少人这样做,我也没有看到相关建议或反对意见,并且我一直都在使用它们。
感谢任何反馈!