php中关于empty()函数是否为真的判断
<?php
// $a = 0; ?==> 符合empty,empty($a)為true
// $a = '0';??==> 符合empty,empty($a)為true
// $a = '';??==> 符合empty,empty($a)為true
// $a = ' ';??==> 不符合empty,empty($a)為flase
// $a = null;??==> 符合empty,empty($a)為true
// $a = 'null';??==> 不符合empty,empty($a)為flase
// $a = true;??==> 不符合empty,empty($a)為flase ?//【易錯】這里不知道為什么沒有報錯,并且還為flase
// $a = 'true';??==> 不符合empty,empty($a)為flase
// $a = flase;??==> 報錯,未定義常量
// $a = 'flase';??==> 不符合empty,empty($a)為flase
// $a = [];??==> 符合empty,empty($a)為true
// $a = array();??==> 符合empty,empty($a)為true ?
if(empty($a)){
echo '符合empty類型';
}else{
echo '不符合empty類型';
}
?>
==》小結一下:常見特殊值都符合empty($a)為true,但非零非空字符串均不符合(包括空格字符串‘ ?’,‘null’,‘true’,‘flase’,但0字符串‘0’和空字符串‘’除外)
轉載于:https://www.cnblogs.com/kernel123/p/9381778.html
總結
以上是生活随笔為你收集整理的php中关于empty()函数是否为真的判断的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 巧用PHP中__get()魔术方法
- 下一篇: C#模拟HTTP POST 请求