PHP比较

  1. PHP函数比较

    PHP函数比较

  2. PHP数据比较

    PHP数据比较

  3. 易错速记

    <?php
    //易错1
    $a = null;
    var_dump(isset($a));      //false
    $b = '0';
    var_dump(empty($b));      //true
    
    //易错2
    var_dump(0 == '0');             //true
    var_dump(0 == '');              //true
    var_dump(0 == null);            //true
    var_dump(0 == []);              //false
    var_dump('0' == '');            //false
    var_dump('0' == null);          //false
    var_dump('0' == []);            //false
    var_dump('' == []);             //false
    var_dump('' == null);           //true
    var_dump([] == null);           //true
    //记忆方法
    // '0' ≠ '' [] null
    // []  ≠ '' 0
    
    // false = 0 '0' '' [] null
    // true  ≠ 0 '0' '' [] null
    
  4. PHP8字符串、数字比较优化

    <?php
    # PHP < 8.0.0
    var_dump(0 == 'abc'); //true
    # PHP ^ 8.0.0
    var_dump(0 == 'abc'); //false
    
Copyright © 豆包嘿嘿~ 2012-∞ 冀ICP备17033181号 all right reserved,powered by Gitbook修订: 21-06-15 16:29

results matching ""

    No results matching ""