Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between isset and empty?

Tags:

What is the difference between !isset and empty, isset and !empty ??

like image 634
yumugee Avatar asked Jun 03 '12 13:06

yumugee


People also ask

What does Isset mean?

Definition and Usage The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL. This function returns true if the variable exists and is not NULL, otherwise it returns false.

What is the difference between NULL and empty in PHP?

A variable is NULL if it has no value, and points to nowhere in memory. empty() is more a literal meaning of empty, e.g. the string "" is empty, but is not NULL .

How check Isset is empty in PHP?

empty() function in PHP ? The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases.

Is empty in PHP?

PHP empty() FunctionThe empty() function checks whether a variable is empty or not. This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0.


2 Answers

The type comparison tables should answer all questions about these operators: http://php.net/manual/en/types.comparisons.php

like image 185
mjhennig Avatar answered Sep 19 '22 13:09

mjhennig


The basic answer would be that a variable can be set (not NULL) and yet be empty(can be assimilated to 0). Consider an empty array for example.

From the link presented by @mjhennig, you can see that 0 is considered to be empty. So is False and the empty string(obviously) :)

like image 34
Samy Arous Avatar answered Sep 22 '22 13:09

Samy Arous