学习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 class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>my_file</FONT></SPAN><SPAN>=@file('non_existent_file')or </SPAN></SPAN><LI class=alt><SPAN>die("Failedopeningfile:errorwas'$php_errormsg'"); </SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>value</FONT></SPAN><SPAN>=@$cache[$key]; </SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></FONT></STRONG></SPAN><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 class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>output</FONT></SPAN><SPAN>=`ls-al`; </SPAN></SPAN><LI class=alt><SPAN>echo"</SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>pre</SPAN><SPAN class=tag>></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></SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></FONT></STRONG></SPAN><SPAN> </SPAN></SPAN></LI></OL>
注:反引号运算符在激活了安全模式或者关闭了shell_exec()时是无效的。
加一/减一运算符:
++$a前加$a的值加一,然后返回$a。
$a++后加返回$a,然后将$a的值加一。
--$a前减$a的值减一,然后返回$a。
$a--后减返回$a,然后将$a的值减一。
这个跟c语言的自加,自减一样举个简单的例子加深一下
立即学习“PHP免费学习笔记(深入)”;
<OL class=dp-xml><LI class=alt><SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>html</SPAN><SPAN class=tag>></SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><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></SPAN><LI class=alt><SPAN></SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>title</SPAN><SPAN class=tag>></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></SPAN><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></SPAN><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></SPAN><LI class=""><SPAN> </SPAN><LI class=alt><SPAN></SPAN><STRONG><FONT color=#006699><SPAN class=tag><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN> </SPAN><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></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>a</FONT></SPAN><SPAN>=++$a; </SPAN></SPAN><LI class=alt><SPAN>echo$a."</SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></SPAN></FONT></STRONG><SPAN>"; </SPAN></SPAN><LI class=""><SPAN> </SPAN><LI class=alt><SPAN>//输出值为4 </SPAN><LI class=""><SPAN> </SPAN><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></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>a</FONT></SPAN><SPAN>=$a++; </SPAN></SPAN><LI class=alt><SPAN>echo$a; </SPAN><LI class=""><SPAN> </SPAN><LI class=alt><SPAN>//输出值为3 </SPAN><LI class=""><SPAN> </SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></FONT></STRONG></SPAN><SPAN> </SPAN></SPAN><LI class=""><SPAN> </SPAN><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></SPAN><LI class=""><SPAN> </SPAN><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></SPAN></LI></OL>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号