if 判断为 false 的 6 种情况

if判断为false的6种情况

class TestController extends Controller
{
    function actionIndex()
    {
        $temp = '';//空字符串
        $this->test_false($temp);

        $temp = '0';//字符串0
        $this->test_false($temp);

        $temp = 0;//整型0
        $this->test_false($temp);

        $temp = 0.00;//浮点型0
        $this->test_false($temp);

        $temp = [];//浮点型0
        $this->test_false($temp);

        $temp = null;//浮点型0
        $this->test_false($temp);
        exit();
    }

    function test_false($data)
    {
        if ($data){
            p('true');
        }else{
            p('false');
        }
    }
}

输出结果:

false
false
false
false
false
false
php
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
1
粉丝
0
喜欢
0
收藏
0
排名:3183
访问:117
私信
所有博文
博客标签
社区赞助商