What is the difference between empty and isset usage in php?

青灯夜游
Release: 2023-02-28 19:06:01
Original
3263 people have browsed it

What is the difference between empty and isset usage in php? The following article will introduce to you the difference between the usage of empty function and isset function in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What is the difference between empty and isset usage in php?

isset

isset returns false only when the variable is null and returns true at any other time

( In PHP, variables are considered to be null. 1. Variables that have not been assigned or initialized. 2. Variables assigned to null)

$null = null; $num = 0; $str = ''; $bool = false; var_dump(isset($null)); // false var_dump(isset($num)); // true var_dump(isset($str)); // true var_dump(isset($bool)); // true
Copy after login

empty

empty determines whether the variable is empty There are 5 situations where it will return true

1, empty string ''

2, number zero 0

3, bool value false

4. null

5. String zero '0'

$null = null; $num = 0; $str = '';$bool = false;var_dump(empty($null)); // true var_dump(empty($num)); // true var_dump(empty($snum)); // true var_dump(empty($str)); // true var_dump(empty($bool)); // true
Copy after login

Summary:

isset only returns no value when the value is null. false

empty will determine the empty value in 5 situations

Note:The parameters of these two functions can only be variables and not constants

empty(0) empty('abc') isset(null)
Copy after login

This way of writing will result in an error

For more related knowledge, please pay attention toPHP Chinese website! !

The above is the detailed content of What is the difference between empty and isset usage in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
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!