php大括号和字符串

Noo*_*ath 3 php string variables brackets

任何人都可以向我解释如何在php字符串中使用花括号{}?喜欢

"this is a {$variable}"
"this is a {$user -> getName($variable);} name"

Gaz*_*ler 8

如果遇到美元符号($),解析器将贪婪地获取尽可能多的令牌以形成有效的变量名称.将变量名称括在花括号中以显式指定名称的结尾.

<?php
$beer = 'Heineken';
echo "$beer's taste is great"; // works; "'" is an invalid character for variable names
echo "He drank some $beers";   // won't work; 's' is a valid character for variable names but the variable is "$beer"
echo "He drank some ${beer}s"; // works
echo "He drank some {$beer}s"; // works
?>
Run Code Online (Sandbox Code Playgroud)

资源