When to wrap curly braces around a variable

前端 未结 3 1512
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 00:51

I don\'t know how to explain this but in simple terms I have seen people using {$variable} when outputting values. I have noticed that {$variable}

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 01:33

    As far as I know, you can use for variable $x

    echo "this is my variable value : $x dollars";
    

    … but if you don't have any spaces between the variable and the text around it, you should use {}. For example:

    echo "this is my variable:{$x}dollars";
    

    because if you wrote it $xdollars it will interpret it as another variable.

提交回复
热议问题