Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在不使用空格或任何其他特殊字符的情况下结束字符串中的变量名?
示例有什么我可以放在$num和st输出之间1st而不是1 st
$num
st
1st
1 st
$num = 1; echo "$num st";
不使用点运算符进行连接
用大括号包裹变量的名称。
$num = 1; echo "${num}st";
或者使用printf语法而不是简单的插值:
printf
$num = 1; printf("%dst", $num);
使用连接.字符:
.
echo $num . 'st';