PHP中的字符串大括号

PHP中的字符串大括号

何谓{ }(大括号)用PHP中的字符串字面值表示?



慕桂英546537
浏览 725回答 3
3回答

函数式编程

对我来说,花括号是连接的替代物,它们是更快类型和代码看起来更干净。记住使用双引号(“)作为内容解析,因为在单引号(‘)中,您将得到文字名称变量数,但须:<?php &nbsp;$a&nbsp;=&nbsp;'12345';//&nbsp;This&nbsp;works: &nbsp;echo&nbsp;"qwe{$a}rty";&nbsp;//&nbsp;qwe12345rty,&nbsp;using&nbsp;braces &nbsp;echo&nbsp;"qwe"&nbsp;.&nbsp;$a&nbsp;.&nbsp;"rty";&nbsp;//&nbsp;qwe12345rty,&nbsp;concatenation&nbsp;used//&nbsp;Does&nbsp;not&nbsp;work: &nbsp;echo&nbsp;'qwe{$a}rty';&nbsp;//&nbsp;qwe{$a}rty,&nbsp;single&nbsp;quotes&nbsp;are&nbsp;not&nbsp;parsed &nbsp;echo&nbsp;"qwe$arty";&nbsp;//&nbsp;qwe,&nbsp;because&nbsp;$a&nbsp;became&nbsp;$arty,&nbsp;which&nbsp;is&nbsp;undefined?>

MM们

例子:$number&nbsp;=&nbsp;4;print&nbsp;"You&nbsp;have&nbsp;the&nbsp;{$number}th&nbsp;edition&nbsp;book";//output:&nbsp;"You&nbsp;have&nbsp;the&nbsp;4th&nbsp;edition&nbsp;book";如果没有大括号,PHP将试图找到一个名为$numberth那是不存在的!
打开App,查看更多内容
随时随地看视频慕课网APP