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

 

posted @ 2020-06-15 09:26  A-GREATE-USERNAME  阅读(1141)  评论(0编辑  收藏  举报