您现在的位置是:首页 > PHP基础

李清波 2017-12-10 PHP基础 2656

PHP中"{}"大括号的用法总结

1、 {} 表示程序块的开始和结束

if ($x==$y) 
{ 
 do_nothing(); 
}


2、 {}用来表示字符串下标

(引用longnetpro兄弟的话)
$s{1}表示字符串

$s的第2个字节(不是第一个)

基本等同于$s[1],只不过后者是老的写法

PHP手册推荐第一种写法


3、分离变量

$s = "Di, "; 
echo ("${s}omething"); 
//Output: Di, omething

而如果用echo ("$something");
那么就会输出 $something 这个变量。 


更多示例


示例一

$var='sky';
echo "{$var}boy";
//输出:skyboy


示例二

$my_str="1234";
$my_str{2}='5';
echo $my_str;


评论

  • 2019-08-23

    4.1 A Lorota Vovô Pedro é qualquer pomada milagrosa.

    回复
  • 2019-08-21

    I just like the helpful info you supply for your articles. I'll bookmark your weblog and take a look at once more here frequently. I'm somewhat certain I'll be told plenty of new stuff right right here! Good luck for the next!

    回复
  • 2019-08-19

    Hi there, You've done a fantastic job. I will certainly digg it and personally suggest to my friends. I'm confident they'll be benefited from this site.

    回复
  • 2019-08-19

    Excellent blog you have here but I was curious if you knew of any forums that cover the same topics talked about here? I'd really love to be a part of online community where I can get responses from other experienced people that share the same interest. If you have any recommendations, please let me know. Thanks a lot!

    回复
  • 2019-08-18

    Yes! Finally something about balms protect.

    回复