Home > Backend Development > PHP Tutorial > PHP and or not

PHP and or not

WBOY
Release: 2016-07-29 09:04:19
Original
5045 people have browsed it

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>
Copy after login

PHP and or not

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template