Which of the following empty functions is php easy to use? In the official php manual, I wrote ,? Check whether a variable is empty. If var is a non-null or non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var, and empty functions that are not prone to php errors
?
According to the official php Manual,
?
Check whether a variable is empty.
If var is a non-null or non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if var is null, TRUE is returned .?
?
Then I solemnly stated in his manual that,
?
Empty () only detects variables, and any non-variables will cause parsing errors. In other words, the following statement does not work: empty (addslashes ($ name )).?
Empty is used to check whether the variable is empty, which is often used in website programming. for example, if we submit the user name on the front-end page, we need to determine whether it is empty, if it is empty, let him submit it again. in this case, we need to use the trim function to filter out spaces on both sides and then use empty for detection.
?
if (empty(trim($_GET['username'])) { …}
?
However, when we run this code, an error is reported. The reason is that"Empty () only detects variables", While trim returns true values, not variables. So an error is reported when empty runs here. The modification method is also very simple. The first method is as follows:
?
if (trim($_GET['username'] == ’‘) { …}
?
The second method adds the intermediate variable:
?
$username = trim($_GET['username']);if (empty($username)) { …}?
The recommended method is to use the verification framework in the project to solve this problem.