Home > Article > Backend Development > How to use empty function in php
The method of using empty function in php is [bool empty (mixed $var)]. The empty() function is used to check whether a variable is empty. If the variable does not exist or the value is equal to false, it will be considered not to exist.
The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.
The empty() function in php is used to check whether a variable is empty. empty() determines whether a variable is considered empty. When a variable does not exist, or its value is equal to FALSE, then it is considered not to exist. empty() does not generate a warning if the variable does not exist.
empty() After version 5.5, it supports expressions, not just variables.
Syntax structure:
bool empty ( mixed $var )
Example:
<?php $ivar1=0; $istr1='phpcncncn'; if (empty($ivar1)){ echo '$ivar1' . " 为空或为 0。" . PHP_EOL; }else{ echo '$ivar1' . " 不为空或不为 0。" . PHP_EOL; }if (empty($istr1)){ echo '$istr1' . " 为空或为 0。" . PHP_EOL; }else{ echo '$istr1' . " 字符串不为空或不为0。" . PHP_EOL; } ?>
Running result:
$ivar1 is empty or 0.
$istr1 The string is not empty or 0.
Free learning video sharing: Introduction to programming
The above is the detailed content of How to use empty function in php. For more information, please follow other related articles on the PHP Chinese website!