Home > Backend Development > PHP Tutorial > Android programmers learn PHP development (3) - loop variables are true, false and not empty - PhpStorm

Android programmers learn PHP development (3) - loop variables are true, false and not empty - PhpStorm

黄舟
Release: 2023-03-06 09:42:01
Original
1130 people have browsed it

Because PHP was produced in 1994, its syntax is a mixture of C, Java, Perl and some of his own programming syntax.
So, students who have basic knowledge of Java before will not have too much trouble learning.

<?php
    /**
     * 变量名以$开始
     * 变量名区分大小写
     */
    $name = "iwanghang";

    for ($x=0; $x<=5; $x++) {
        echo $name .$x."<br>";
    }
    /** 上面的for循环的打印结果,如下:
        iwanghang0
        iwanghang1
        iwanghang2
        iwanghang3
        iwanghang4
        iwanghang5 */

    /**
     * var_dump 打印一个变量的类型和值
     * 看下面3个例子
     */
    var_dump($name); // 打印结果:string(9) "iwanghang"
    echo "<br>x = ".$x."<br>"; // 打印结果:x = 6
    var_dump($x); // 打印结果:int(6)
    echo "<br>";
    var_dump(666); // 打印结果:int(666)
    echo "<br>";

    /**
     * isset 判断真假
     */
    $nameInit = isset($name);
    var_dump($nameInit); // 打印结果:bool(true)
    echo "<br>";
    $nameInit1 = isset($name1);
    var_dump($nameInit1); // 打印结果:bool(false)
    echo "<br>";

    /**
     *  布尔值(真假)判断
     */
    if(isset($name)){
        echo "真<br>"; // 打印结果:真
    }else{
        echo "假<br>";
    }
    if(isset($name1)){
        echo "真<br>";
    }else{
        echo "假<br>"; // 打印结果:假
    }

    /**
     * 为空判断
     */
    if(empty($name)){
        echo "空<br>";
    }else{
        echo "非空<br>"; // 打印结果:非空
    }
    if(empty($name1)){
        echo "空<br>"; // 打印结果:空
    }else{
        echo "非空<br>";
    }

    /**
     * x等于6
     * empty($x)为非空
     * var_dump(empty($x))返回布尔值为假
     *
     * x1不存在
     * empty($x1)为空
     * var_dump(empty($x1))返回布尔值为真
     */
    echo $x."<br>"; // 打印结果:6
    echo "".empty($x)."<br>"; // 打印结果:
    var_dump(empty($x)); // 打印结果:bool(false)
    echo "<br>------<br>";

    echo "".empty($x1)."<br>"; // 打印结果:1
    var_dump(empty($x1)); // 打印结果:bool(true)
Copy after login

The above is the content of Android programmers learning PHP development (3) - loop variables are true, false and not empty - PhpStorm. For more related content, please pay attention to 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