zoukankan      html  css  js  c++  java
  • PHP 真值与空值

    本文参考 http://php.net/manual/en/types.comparisons.php

    1. isset

    bool isset ( mixed $var [, mixed $... ] )

    Determine if a variable is set and is not NULL.
    变量值被设置,而且其值不为 NULL,那么就会返回 true。

    另外这个函数可以被用来检查数组中的元素是否存在且值不为 NULL。

    2. empty

    bool empty ( mixed $var )

    A variable is considered empty if it does not exist or if its value equals FALSE. empty() does not generate a warning if the variable does not exist.
    变量不存在或者其值为 FALSE,empty 函数都返回真。另外 empty 只能处理变量,无法处理表达式的结果。

    3. PHP 中一些奇怪的值【背下来】

    1 $x = '';                // 为 false
    2 $x = null;              // 没有值,没有类型,为 false
    3 var $x;                 // 没有值,没有类型,为 false
    4 $x is undefined;        // 没有值,没有类型,为 false
    5 $x = array();           // 为 false
    6 $x = false;             // 为 false
    7 $x = 0;                 // 为 false
    8 $x = '0';               // 为 false
    9 $x = 'false'            // 为 true

    上面这些值得真值测试都是 loose comparison。

  • 相关阅读:
    MySQL 分组
    MySQL LIKE 子句
    MySQL DELETE 语句
    MySQL UPDATE 查询
    MySQL where 子句
    MySQL 插入数据
    MySQL 查询数据
    MySQL 删除数据表
    MySQL 创建数据表
    MySQL 数据类型
  • 原文地址:https://www.cnblogs.com/wendellyi/p/8798213.html
Copyright © 2011-2022 走看看