PHP细节,empty,is_null,isset,if()

以下内容转载自http://wuxinjie.github.io/php-04/

  • 从下表可知,empty与if()完全相反,is_null与isset完全相反
  • isset是语句,is_null是函数,因此isset执行速度远远大于isnull
  • 因为是函数,is_null可以作为可变函数调用,也可以接受函数返回值作为参数,isset统统不行。
  • 同样因为执行速度,建议使用 “=== NULL” 来代替isnull
  • 什么时候用哪个呢?我的建议是哪个方便用哪个。
表达式gettype()empty()is_null()isset()boolean : if($x)
$x = “”; string TRUE FALSE TRUE FALSE
$x = NULL NULL TRUE TRUE FALSE FALSE
var $x; NULL TRUE TRUE FALSE FALSE
$x 尚未定义 NULL TRUE TRUE FALSE FALSE
$x = array(); array TRUE FALSE TRUE FALSE
$x = false; boolean TRUE FALSE TRUE FALSE
$x = true; boolean FALSE FALSE TRUE TRUE
$x = 1; integer FALSE FALSE TRUE TRUE
$x = 42; integer FALSE FALSE TRUE TRUE
$x = 0; integer TRUE FALSE TRUE FALSE
$x = -1; integer FALSE FALSE TRUE TRUE
$x = “1”; string FALSE FALSE TRUE TRUE
$x = “0”; string TRUE FALSE TRUE FALSE
$x = “-1”; string FALSE FALSE TRUE TRUE
$x = “php”; string FALSE FALSE TRUE TRUE
$x = “true”; string FALSE FALSE TRUE TRUE
$x = “false”; string FALSE FALSE TRUE TRUE

 

posted @ 2019-03-12 11:29  html55  阅读(379)  评论(0编辑  收藏  举报