プログラムの演算では、値を機械語(バイナリ)に変換し、これを元にANDやNOTを加算してバイナリで演算します。
$
と 1$0=0
または |
1|0=1
違うよ〜
~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>
以上、PHP の長所と短所を側面も含めて紹介しましたが、PHP チュートリアルに興味のある友人の参考になれば幸いです。