isset()
and! The empty()
function is similar, both will return the same result. But the only difference is! Theempty()
function does not generate any warnings or electronic notifications when the variable does not exist. It's enough to use either function. By merging two functions into a program it causes time lapse and unnecessary memory usage.
1.isset()
isset ( mixed $var , mixed $... = ? ) : bool
var: The variable to be checked.
Return value: If var exists and the value is not null, return true, otherwise return false.
PS:If a variable has been released usingunset()
, it will no longer be isset(). Ifisset()
is used to test a variable that is set to null, false will be returned. At the same time, it should be noted that thenull
character ("\0") is not equivalent to the null constant ofPHP
. If multiple parameters are passed in at one time, thenisset()
will only return when all parameters are settrue
The calculation process is from left to right, and when an unset variable is encountered midway will stop immediately.
"; // 声明一个空数组 $array = array(); echo isset($array['geeks']) ? 'array is set.' : 'array is not set.'; ?>
Output:
0 is set with isset functionarray is not set. array is not set.
##2.empty()
empty ( mixed $var ) : bool
falseOtherwise return
true.
0 is considered empty 1 is considered set
3. Similarities and differences between the twoisset() and
! The empty()function is similar, both will return the same result. But the only difference is! Theempty()
function does not generate any warnings or electronic notifications when the variable does not exist. It's enough to use either function. By merging two functions into a program it causes time lapse and unnecessary memory usage.
Copy after login
0 is set with isset function 1 is set with !empty function
Copy after login
Recommended: "php video tutorial" "php tutorial"
The above is the detailed content of Similarities and differences between isset() and !empty() functions in PHP. For more information, please follow other related articles on the PHP Chinese website!
Related labels:
source:php.cn
Previous article:Consistent persistence, PHP’s better solution to data update
Next article:Share error sets and solutions when compiling PHP source code
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
Latest Articles by Author
-
2023-03-09 14:14:01
-
2023-03-09 14:12:02
-
2023-03-09 14:10:01
-
2023-03-09 14:08:01
-
2023-03-09 13:46:01
-
2021-05-07 15:10:23
-
2023-03-09 13:18:02
-
2023-03-09 13:16:02
-
2023-03-09 13:14:01
-
2023-03-09 13:12:01
Latest Issues
isset() and empty() - what to use
Can you help me improve my coding style? :) In some tasks I need to check - if a variable ...
From 2023-10-16 20:54:57
0
2
231
Popular Recommendations
Popular Tutorials
More>
-
-
-
JAVA Beginner's Video Tutorial
2367556
-
-
Latest Downloads
More>
-
-
-
-
-
-
-
-
-
About us
Disclaimer
Sitemap
-
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!