Home > Backend Development > PHP Tutorial > Android programmers learn PHP development (5)-Boolean scientific notation-PhpStorm

Android programmers learn PHP development (5)-Boolean scientific notation-PhpStorm

黄舟
Release: 2023-03-06 09:46:01
Original
1345 people have browsed it

In addition to the following code, I also want to talk about floating point numbers. Float is an approximate number. For example, in java or js, if 0.1 is added 10 times, the result is 1.0000001, not 1.

<?php
    /**
     * 变量类型
     * 布尔值boolean
     * 顺带介绍科学计数法
     */
    $bool = true;
    $bool2 = false;
    $bool3 = 0; // 打印结果:int(0) --- 假
    $bool4 = 0.0; // 打印结果:float(0) --- 假
    $bool5 = 0.00; // 打印结果:float(0) --- 假
    $bool6 = ""; // 打印结果:string(0) "" --- 假
    $bool7 = " "; // 打印结果:string(1) " " --- 真
    $bool8 = "0"; // 打印结果:string(1) "0" --- 假
    $bool9 = "0.0"; // 打印结果:string(3) "0.0" --- 真
    $bool10 = "0.00"; // 打印结果:string(4) "0.00" --- 真
    $bool11 = array();  // 打印结果:array(0) { } --- 假
    $bool12 = array(0);  // 打印结果:array(1) { [0]=> int(0) } --- 真
    $bool13 = new Iwanghang;  // 打印结果:object(Iwanghang)#1 (0) { } --- 真
    class Iwanghang{}
    $bool14 = ord("hello world");  // 打印结果:int(104) --- 真 , ord() 函数返回字符串的首个字符的 ASCII 值。
    $bool15 = 1.2e3;  // 打印结果:float(1200) --- 真 , 相当于1.2*(10的3次方)
    $bool16 = 7E-10+1;  // 打印结果:float(1.0000000007) --- 真 , 相当于7*(10的-10次方)加上1
    $bool17 = 3E+5;  // 打印结果:float(300000) --- 真 , 相当于7*(10的-10次方)
    $bool18 = 0.00000000006;  // float(6.0E-11) --- 真
    $bool19 = 3E-3;  // float(0.003) --- 真 , 数位小可以正常显示0.003 , $bool16太长了 , 如果不加1会显示科学计数法

    var_dump($bool); // 打印结果:bool(true)
    echo "<br>";
    var_dump($bool2); // 打印结果:bool(false)
    echo "<br>";
    var_dump($bool3); // 打印结果:int(0) --- 假
    if ($bool3){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool4); // 打印结果:float(0) --- 假
    if ($bool4){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool5); // 打印结果:float(0) --- 假
    if ($bool5){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool6); // 打印结果:string(0) "" --- 假
    if ($bool6){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool7); // 打印结果:string(1) " " --- 真
    if ($bool7){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool8); // 打印结果:string(1) "0" --- 假
    if ($bool8){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool9); // 打印结果:string(3) "0.0" --- 真
    if ($bool9){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool11); // 打印结果:array(0) { } --- 假
    if ($bool11){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool12); // 打印结果:array(1) { [0]=> int(0) } --- 真
    if ($bool12){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool13); // 打印结果:object(Iwanghang)#1 (0) { } --- 真
    if ($bool13){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool14); // 打印结果:int(104) --- 真
    if ($bool14){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool15); // 打印结果:float(1200) --- 真
    if ($bool15){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool16); // 打印结果:float(1.0000000007) --- 真
    if ($bool16){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool17); // 打印结果:float(300000) --- 真
    if ($bool17){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool18); // 打印结果:float(6.0E-11) --- 真
    if ($bool18){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
    var_dump($bool19); // 打印结果:float(0.003) --- 真
    if ($bool19){echo "--- 真";}else{echo "--- 假";};
    echo "<br>";
Copy after login

The above is the content of Android programmers learning PHP development (5)-Boolean scientific notation-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