Android programmers learn PHP development (9)-assignment comparison logical operations-PhpStorm

黄舟
Release: 2023-03-06 09:54:02
Original
1291 people have browsed it

Assignment operator symbols: =, +=, -=, *=, /=, %=, .=
Comparison operator symbols: >, <, ==, >=, < ;=, ===, !=, !==
Logical operators and or &&, or or ||, not or!, xor
xor Different is true, the same is false
die() Output a message and exit the current script


<?php
    /**
     * 赋值运算符号:=,+=,-=,*=,/=,%=,.=
     */
    $a = 5;
    $name = "iwanghang"+5; // 打印结果:5
    $name2 = "iwanghang"+$a; // 打印结果:5
    echo $name."<br>";
    echo $name2."<br>";

    $a += 1; // 等同于 $a = $a + 1; 打印结果:6
    echo $a."<br>";
    $a -= 1; // 等同于 $a = $a - 1; 打印结果:5
    echo $a."<br>";

    /**---------------分割线---------------*/
    $str = "王航";
    $str2 = "安卓";
    echo $str.$str2."<br>"; // 打印结果:王航安卓
    //echo $str.$str2.5."<br>"; // 不可以直接连接5
    echo $str.$str2.$a."<br>"; // 但是可以连接$a($a的值为5),打印结果:王航安卓5
    echo "王航安卓{$a}<br>"; // 打印结果:王航安卓5
    echo "王航安卓".$a."<br>"; // 打印结果:王航安卓5
    echo &#39;王航安卓&#39;.$a.&#39;<br>&#39;; // 打印结果:王航安卓5
    echo &#39;王航安卓{$a}<br>&#39;; // 打印结果:王航安卓{$a}
    echo "王航安卓",$a,"<br>"; // 打印结果:王航安卓5

    $str .= "是"; // 打印结果:王航是
    echo $str."<br>";
    $str .= "安卓程序员"; // 打印结果:王航是安卓程序员
    echo $str."<br>";

    /**---------------分割线---------------*/
    $html = &#39;<html>&#39;;
    $html .= &#39;<body>&#39;;
    $html .= "<h1>CSDN</h1>";
    $html .= &#39;</body>&#39;;
    $html .= &#39;</html>&#39;;
    echo $html."<br>"; // 打印结果:CSDN (一级标题)

    /**
     * 比较运算符号:>,<,==,>=,<=,===,!=,!==
     */
    $a = "007";
    $b = 7;
    var_dump($a===$b); // 打印结果:bool(false) , 全等于判断(变量类型也需要相同)
    echo "<br>";
    var_dump($a==$b); // 打印结果:bool(true) , 等于判断
    echo "<br>";
    var_dump($a=$b); // 打印结果:int(7) , 赋值运算
    echo "<br>";

    /**
     * 逻辑运算符 and或者&&、or或||、not或!、xor
     * xor 不同为真,相同为假
     */
    var_dump(true && true); // 打印结果:bool(true)
    echo "<br>";
    var_dump(true && false); // 打印结果:bool(false)
    echo "<br>";
    var_dump(true || false); // 打印结果:bool(true)
    echo "<br>";
    var_dump(!true); // 打印结果:bool(false)
    echo "<br>";
    var_dump(!false); // 打印结果:bool(true)
    echo "<br>";
    var_dump(true xor false); // 打印结果:bool(true)
    echo "<br>";
    var_dump(false xor true); // 打印结果:bool(true)
    echo "<br>";
    var_dump(true xor true); // 打印结果:bool(false)
    echo "<br>";
    var_dump(false xor false); // 打印结果:bool(false)
    echo "<br>";

    /**---------------分割线---------------*/
    $year = 2016;
    if ($year%4==0 && $year%100!==0 || $year%400!==0 ){
        echo "这个年{$year}是闰年<br>"; // 打印结果:这个年2016是闰年
    }else {
        echo "这个年{$year}是平年<br>";
    }

    /**---------------分割线---------------*/
    //die("输入并退出程序!"); // 打印结果:输入并退出程序!
    //echo "666666"; // 这一行不会输出

    /**---------------分割线---------------*/
    //$link = mysql_connect("localhost","root","") or die("数据库连接失败!");

    /**---------------分割线---------------*/
    $a = 0;
    $b = 0;
    if ($a=3 && $b=3){
        $a++;
        $b++;
    }
    echo $a.",".$b."<br>"; // 打印结果:1,4

    /**---------------分割线---------------*/
    $a = 0;
    $b = 0;
    if ($a=3 || $b=3){
        $a++;
        $b++;
    }
    echo $a.",".$b."<br>"; // 打印结果:1,1

    /**---------------分割线---------------*/
    $a = 0;
    $b = 0;
    if ($a==3 || $b==3){
        $a++;
        $b++;
    }
    echo $a.",".$b."<br>"; // 打印结果:0,0
Copy after login

The above is the content of Android programmers learning PHP development (9)-Assignment comparison logical operation-PhpStorm. For more related content, please Follow the PHP Chinese website (www.php.cn)!



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!