#What does empty mean in php?
empty means empty, it is a built-in function in php, 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.
Version requirements: PHP 4, PHP 5, PHP 7
Basic syntax:
empty ( $var )
Parameters: empty() The function accepts a single argument, as shown in the syntax above, as described below.
$ var: Variable used to check if it is empty.
Return value: Return false when $var exists and has a non-null non-zero value. Otherwise return true.
Note: Under PHP 5.5, the empty() function only supports variable checking, and anything else will cause a parsing error.
Simple example of empty() function
Let’s use an example to introduce how the empty() function uses to determine whether a variable is empty
<?php header("content-type:text/html;charset=utf-8"); echo "<br>"; $var1 = NULL; $var2 = ""; $var3 = "PHP中文网"; empty($var1) ? print_r("变量var1为空<br>") : print_r("变量var1不为空<br>"); empty($var2) ? print_r("变量var2为空<br>") : print_r("变量var2不为空<br>"); empty($var3) ? print_r("变量var3为空<br>") : print_r("变量var2不为空,值为:".$var3); ?>
Output:
Explanation:
The following will be used by the empty() function Values considered null:
1, "" (empty string)
2, 0 (0 as an integer)
3, 0.0 (0 as a floating point number )
4, "0" (0 as a string)
5, null
6, false
7, array() (an empty Array)
For more PHP related knowledge, please visit php中文网!
The above is the detailed content of What does empty mean in php?. For more information, please follow other related articles on the PHP Chinese website!