Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between 'isset()' and '!empty()' in PHP?

Tags:

php

isset

I don't understand the difference between isset() and !empty().

Because if a variable has been set, isn't it the same as not being empty?

like image 603
Vitalynx Avatar asked Dec 14 '13 11:12

Vitalynx


People also ask

Should I use isset or empty?

isset() : You can use isset() to determine if a variable is declared and is different than null . empty() : It is used to determine if the variable exists and the variable's value does not evaluate to false . is_null() : This function is used to check if a variable is null .

What is the difference between isset and unset in PHP?

Both of them are variable handling functions and have similar syntax. However, they differ in their functionalities. While isset() function specifies whether a variable is declared or set in the php script and doesn't have a null value, an unset() function clears or unset the defined variable in the php script.

Does Isset check for empty string?

"isset() checks if a variable has a value including (False, 0 or empty string), but not NULL.

Does PHP empty check Isset?

The isset() and ! empty() functions are similar and both will return the same results. But the only difference is ! empty() function will not generate any warning or e-notice when the variable does not exists.


2 Answers

ISSET checks the variable to see if it has been set. In other words, it checks to see if the variable is any value except NULL or not assigned a value. ISSET returns TRUE if the variable exists and has a value other than NULL. That means variables assigned a "", 0, "0", or FALSE are set, and therefore are TRUE for ISSET.

EMPTY checks to see if a variable is empty. Empty is interpreted as: "" (an empty string), 0 (integer), 0.0 (float)`, "0" (string), NULL, FALSE, array() (an empty array), and "$var;" (a variable declared, but without a value in a class.

For more information, see this article

like image 80
Nambi Avatar answered Oct 18 '22 04:10

Nambi


Source :http://php.net/manual/en/types.comparisons.phpThis page shows the comparison of the empty(),is_null(),isset().

The picture showing complete comparison here

like image 20
Black Mamba Avatar answered Oct 18 '22 04:10

Black Mamba