php 为空时为空? [英] php is null when empty?

查看:36
本文介绍了php 为空时为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have a question regarding NULL in PHP:

  $a = '';
  if($a == NULL) {
      echo 'is null';
  }

Why do I see is null when $a is an empty string? Is that a bug?

解决方案

What you're looking for is:

if($variable === NULL) {...}

Note the ===.
When use ==, as you did, PHP treats NULL, false, 0, the empty string, and empty arrays as equal.

这篇关于php 为空时为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆