Home >Backend Development >PHP Tutorial >How to determine PHP operator precedence_PHP tutorial
When learning PHP, you may encounter the problem of PHP operator priority. Here we will introduce the solution to the problem of PHP operator priority, and share it with you here. PHP supports an error control operator: @. When placed before a PHP expression, any error message that expression may produce is ignored. If the track_errors feature is activated, any error messages generated by the expression are stored in the variable $php_errormsg. This variable is overwritten on every error, so check it as early as possible if you want to use it.
<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>?></span></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 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> <li class=""> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
Note: The backtick operator is invalid when safe mode is activated or shell_exec() is turned off.
Add one/subtract one operator:
Add $a before ++$a, add one to the value of $a, and then return $a.
Add $a++ to return $a, and then increase the value of $a by one.
--Decrease the value of $a by one before $a, and then return $a.
$a--After subtracting, return $a, and then decrement the value of $a by one.
This is the same as self-increment and self-decrement in C language. Let’s take a simple example to deepen it
<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> <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><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> </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><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>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> </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>