php basics
PHP empty
The PHP empty function is used to check whether the variable is empty. If the variable to be checked is non-empty or non-zero, the empty function will return FALSE. This is slightly different from the isset function, such as empty value, "0 ", 0, array(), FALSE, NULL, var $var; etc. will be treated as empty by the empty function.
PHP empty syntax example
bool empty (variable to check)
The "variable to be checked" in the syntax can be variable or array ( Array ), and the empty function can be checked. This is similar to the isset function, except that the result of the check may be different according to the value of the variable. Must pay more attention to the situation at the time and choose.
PHP empty implementation example
<?php
$var1 = 0;
if (empty($var)) {
echo'The variable is empty';
}
$var2 = array();
if (empty($var2)) {
echo'The variable is empty';
}
? >
Both of these simple examples will output the result "Variable is empty". Why? First, explain the first variable $var1. Since we preset $var1=0, $var1 is set under the rules of isset, but in the empty function, 0 is also empty; then $var2 is an empty array array(), so the empty check also returns true.$var1 = 0;
if (empty($var)) {
echo'The variable is empty';
}
$var2 = array();
if (empty($var2)) {
echo'The variable is empty';
}
? >
Post a Comment
0 Comments