沃梦达 / 编程问答 / php问题 / 正文

php 为空时为空?

php is null when empty?(php 为空时为空?)

本文介绍了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 为空时为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:php 为空时为空?

基础教程推荐