In program operations, values are converted into machine codes (binary) and then added, and AND or NOT are based on this basis and are operated in binary.
with $
1$0=0
or |
1|0=1
Not ~
~1=0
<code><span><?php </span><span>//四个变量分别代表四盏灯的开关</span><span>$l_one</span> = <span>1</span>; <span>$l_two</span> = <span>2</span>; <span>$l_three</span> = <span>4</span>; <span>$l_four</span> = <span>8</span>; <span>//$sta代表四盏灯的状态</span><span>$sta</span> = <span>3</span>; <span>//输出灯开的号码</span> light_sta(<span>$sta</span>); <span>//若要开启第四盏灯</span><span>echo</span><span>'开启第四盏灯:'</span>; <span>$sta_n</span> = <span>$sta</span>|<span>$l_four</span>; light_sta(<span>$sta_n</span>); <span>//若要关闭第一盏灯</span><span>echo</span><span>'关闭第一盏灯:'</span>; <span>$sta_o</span> = <span>$sta</span>&~<span>$l_one</span>; light_sta(<span>$sta_o</span>); <span>//输出灯开的号码</span><span><span>function</span><span>light_sta</span><span>(<span>$sta</span>)</span>{</span><span>//四个变量分别代表四盏灯的开关</span><span>$l_one</span> = <span>1</span>; <span>$l_two</span> = <span>2</span>; <span>$l_three</span> = <span>4</span>; <span>$l_four</span> = <span>8</span>; <span>echo</span><span>'light on: '</span>; <span>if</span>(<span>$sta</span>&<span>$l_one</span>){ <span>echo</span><span>'1 '</span>; }<span>if</span>(<span>$sta</span>&<span>$l_two</span>){ <span>echo</span><span>'2 '</span>; }<span>if</span>(<span>$sta</span>&<span>$l_three</span>){ <span>echo</span><span>'3 '</span>; }<span>if</span>(<span>$sta</span>&<span>$l_four</span>){ <span>echo</span><span>'4'</span>; } <span>echo</span><span>''</span>; }</span></code>
The above has introduced the pros and cons of PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.