Home  >  Article  >  Backend Development  >  This article mainly shares with you several methods of determining whether a variable is empty in PHP. I hope it can help you. Whether it is empty method

This article mainly shares with you several methods of determining whether a variable is empty in PHP. I hope it can help you. Whether it is empty method

小云云
小云云Original
2018-03-16 15:05:481409browse

This article mainly shares with you several PHP methods to determine whether a variable is empty. I hope it can help you.

  • Use if()

$a=1;if($a)     值为true$a='a';
if($a)     值为true$a='';
if($a)     值为false$a=0;
if($a)     值为false$a=null;
if($a)     值为false
  • empty

$a=1;if(!empty($a))     值为true$a='a';
if(!empty($a))     值为true$a='';
if(!empty($a))     值为false$a=0;
if(!empty($a))     值为false$a=null;
if(!empty($a))     值为false
  • Comparison of several other functions
    This article mainly shares with you several methods of determining whether a variable is empty in PHP. I hope it can help you. Whether it is empty method

Related recommendations:

php determines variable type

Variable type Common methods for judging variable types in php

Common methods for judging variable types in php_PHP tutorial

The above is the detailed content of This article mainly shares with you several methods of determining whether a variable is empty in PHP. I hope it can help you. Whether it is empty method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn