Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

isset vs. empty

Status
Not open for further replies.

leegold2

Technical User
Oct 10, 2004
116
isset vs. empty

I'm trying to find a simple explanation and simple examples on what the difference is between these two functions. Appreciate any easy to understand help.

Thanks
 
isset() will tell you whether the variable has been instantiated. empty() will tell you if an existing variable has a value.

For example, if

$a = "foo";
$b = "";

then

isset ($a) will return TRUE
isset ($b) will return TRUE
isset ($c) will return FALSE

empty ($a) will return FALSE
empty ($b) will return TRUE
empty ($c) will, I think, return a warning.

Read the PHP online manual entry for empty() (




Want the best answers? Ask the best questions! TANSTAAFL!
 
empty($c) will return true.

an uninstantiated variable is empty for the purposes of the function.

i use isset as a more granular form of empty when i really want to know whether a variable exists (ie form submission).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top