Curly braces in string in PHP

后端 未结 5 733
刺人心
刺人心 2020-11-21 23:13

What is the meaning of { } (curly braces) in string literals in PHP?

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-21 23:44

    Example:

    $number = 4;
    print "You have the {$number}th edition book";
    //output: "You have the 4th edition book";
    

    Without curly braces PHP would try to find a variable named $numberth, that doesn't exist!

提交回复
热议问题