@H_502_0@<span style="background-color: #ccffcc">
实例如下:
<div class="jb51code">
<pre class="brush:xhtml;">
<?PHP //点和逗号的测试,涉及到字符串的强制转换
echo 1+5;
echo "
";
echo '1+5='."1+5"."
";
echo '1+5='."5+1","
";
echo '1+5=',1,"
"; //用逗号,不需要空格
echo '1+5='. 1,"
"; //用连接符,需要空格,否则报错
echo '1+5=',100+200,"
"; //用逗号,常用于输出多个变量,不影响输出
//省去了字符串拼接的步骤,理论上在 echo 的时候用“逗号”会快一点。
//换成用连接符,注意了,看以下测试:
echo '注意了!
';
echo '1+5='. 100,"
"; //注意 .和100之间需要空格,否则报错
echo '1+5='. 200,"
";
echo '1+5='. 100+200,"
"; //此处结果开始异常了
echo '1+5='. 200+100,"
";
echo ('1+5='. 200)+100,"
"; //从与上面的结果相同可以看出,连接符的优先级高于运算符
echo "
";
//先来看看字符串的强制转换
echo (int)'abc1'; echo "
";
echo (int)'1abc'; echo "
";
echo (int)'22abc'; echo "
";
//结果:将一个字符串强制转换成一个数字,PHP会去搜索这个字符串的开头,
//如果开头是数字就转换,如果不是就直接返回0.
//回到测试的问题
echo '结果分析:';
echo '1+5='. 100+200,"
";
/* 程序是这样执行的,