What is the method in PHP to check if a variable is empty?

In PHP, you can check if a variable is empty using the following methods:

  1. Check if the object is empty.
  2. is not filled
  3. Return true if the given array or string is empty.
  4. It is true.
$var = '';
if(empty($var)) {
    echo '变量为空';
} else {
    echo '变量不为空';
}
  1. determine if a variable is set
  2. Check if a variable is set or not.
  3. Check if a variable is set and is not NULL
  4. correct
$var = '';
if(isset($var)) {
    echo '变量已设置';
} else {
    echo '变量未设置';
}
  1. Does it equal null?
  2. checks if a variable is null
$var = null;
if(is_null($var)) {
    echo '变量为 null';
} else {
    echo '变量不为 null';
}

These methods can be selected based on specific needs.

bannerAds