Home  >  Article  >  Backend Development  >  php编程基础之isset与empty

php编程基础之isset与empty

WBOY
WBOYOriginal
2016-07-25 08:58:05959browse
本文介绍下,php编程基础中最常用的二个函数isset与empty,举几个例子,供大家学习参考。

在基础php编程中,最常用的两个函数,isset函与empty函数,实例如下:

 $val)
    {
        echo isset($val) ? 'true': 'false';
        echo "\t";
        echo empty($val) ? 'true': 'false';
        echo "\n";
    }
?>

输出结果: isset empty ------------------------------- true true true true false true false true true true true false 有时在表单输入时,尤其是在做配置时,当填入0时,代表的是值是0,但不填值表示的可能是该值未定义。 此种情况可以用以下函数作判断:

输出结果: 00 可以看到输入0已不再被认为是空了,不论其是字符还是数字。

怎么样,有了以上的二个例子,对于php函数isset与empty函数的更爱,是不是又深了一层呢?!



Statement:
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