学习PHP时,你可能会遇到PHP运算符优先级问题,这里将介绍PHP运算符优先级问题的解决方法,在这里拿出来和大家分享一下。PHP支持一个错误控制运算符:@。当将其放置在一个PHP表达式之前,该表达式可能产生的任何错误信息都被忽略掉。如果激活了track_errors特性,表达式所产生的任何错误信息都被存放在变量$php_errormsg中。此变量在每次出错时都会被覆盖,所以如果想用它的话就要尽早检查。
<ol class="dp-xml"> <li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">my_file</font></span><span>=@file('non_existent_file')or </span> </li> <li class="alt"><span>die("Failedopeningfile:errorwas'$php_errormsg'"); </span></li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">value</font></span><span>=@$cache[$key]; </span> </li> <li class="alt"> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
<ol class="dp-xml"> <li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">output</font></span><span>=`ls-al`; </span> </li> <li class="alt"> <span>echo"</span><strong><font color="#006699"><span class="tag"><span class="tag-name">pre</span><span class="tag">></span></span></font></strong><span>$output</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">pre</span><span class="tag">></span></font></strong><span>"; </span> </li> <li class=""> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
注:反引号运算符在激活了安全模式或者关闭了shell_exec()时是无效的。
加一/减一运算符:
++$a前加$a的值加一,然后返回$a。
$a++后加返回$a,然后将$a的值加一。
--$a前减$a的值减一,然后返回$a。
$a--后减返回$a,然后将$a的值减一。
这个跟c语言的自加,自减一样举个简单的例子加深一下
<ol class="dp-xml"> <li class="alt"><span><strong><font color="#006699"><span class="tag"><span class="tag-name">html</span><span class="tag">></span></span></font></strong><span> </span></span></li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">head</span><span class="tag">></span></span></font></strong><span> </span> </li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">title</span><span class="tag">></span></span></font></strong><span>php常量定义--阿涛随笔</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span></font></strong><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">head</span><span class="tag">></span></font></strong><span> </span> </li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">body</span><span class="tag">></span></span></font></strong><span> </span> </li> <li class=""><span> </span></li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span> </li> <li class=""><span> </span></li> <li class="alt"> <span>$</span><span class="attribute"><font color="#ff0000">a</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">3</font></span><span>; </span> </li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">a</font></span><span>=++$a; </span> </li> <li class="alt"> <span>echo$a."</span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">></span></span></font></strong><span>"; </span> </li> <li class=""><span> </span></li> <li class="alt"><span>//输出值为4 </span></li> <li class=""><span> </span></li> <li class="alt"> <span>$</span><span class="attribute"><font color="#ff0000">a</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">3</font></span><span>; </span> </li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">a</font></span><span>=$a++; </span> </li> <li class="alt"><span>echo$a; </span></li> <li class=""><span> </span></li> <li class="alt"><span>//输出值为3 </span></li> <li class=""><span> </span></li> <li class="alt"> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> <li class=""><span> </span></li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">body</span><span class="tag">></span></font></strong><span> </span> </li> <li class=""><span> </span></li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">html</span><span class="tag">></span></font></strong><span> </span> </li> </ol>