$username = 'king';
//echo "my name is $kings";
echo "my name is {$username}s";//my name is kings
echo "<hr/>";
echo "my name is ${username}s";//my name is kings
查询 修改
$str = 'abcdef';
echo $str{0};//a
echo "<hr/>";
$str{1} = 'm';
echo $str;//amcdef
echo "<hr/>";
//只能用一个字符修改一个字符
$str{4} = 'hello';
echo $str;//amcdhf
echo "<hr/>";
//中文在UTF8下占三个字符
$str = "你好";
echo $str{0};
echo $str{1};
echo $str{2};//你
删除
$str = "imooc";
$str{1} = '';
echo $str . "<br/>"; //iooc
var_dump($str); //string 'i�ooc' (length=5)
添加
$str = 'abc';
$str{3} = 'def';
echo $str . "<br/>";//abcd
$str{5} = "fgh";
echo $str . "<br/>";//abcd f
var_dump($str);//string 'abcd f' (length=6)
[]与{}效果相同
$str = 'hello';
echo $str[0] . "<br/>";//h
$string = 'sdsdsdsdkjfkgjfjkgfj';
echo $string{mt_rand(0, strlen($string) - 1)};//g
思考:产生4位验证码