php check if variable is empty

(*-*)浩
Release: 2023-02-24 20:48:01
Original
2025 people have browsed it

php check if variable is empty

Determine whether the value is empty after retrieving it from the database. This seems very simple. Just compare it with null, but it is not the case (recommended learning: PHP Programming from Beginner to master)

if($obj==null){ 
}
Copy after login

Writing like this will report an error: Notice: Trying to get property of non-object problem,

After checking, I found that I need to use the following writing

if (isset($obj)) { 
echo "This var is set set so I will print."; 
}
Copy after login

What does this isset do?

isset function is to detect whether the variable is set.

格式:bool isset ( mixed var [, mixed var [, ...]] )
Copy after login

Return value:

If the variable does not exist, return FALSE

If the variable exists and its value is NULL, also returns FALSE

If the variable exists and the value is not NULL, TRUE is returned

When multiple variables are checked at the same time, each single item is TRUE is returned only when the previous requirement is met, otherwise the result is FALSE

If a variable has been released using unset(), it will no longer be isset(). If you use isset() to test a variable that is set to NULL, it will return FALSE. Also note that a NULL byte ("\0") is not equivalent to PHP's NULL constant.

Warning: isset() can only be used with variables, because passing any other parameters will cause a parsing error. If you want to check whether a constant has been set, use the defined() function.

It seems that the problem with my judgment just now is because this "is a NULL byte ("\0") and is not equivalent to PHP's NULL constant".

The above is the detailed content of php check if variable is empty. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!