Friday, September 11, 2015

isset() VS empty() - which one I'll use!!!!

It depends what you are looking for, if you are just looking to see if it is empty just use empty as it checks whether it is set as well, if you want to know whether something is set or not use isset.
Empty checks if the variable is set and if it is it checks it for null, "", 0, etc
Isset just checks if is it set, it could be anything not null
With empty, the following things are considered empty:
  • "" (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • "0" (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)
  • var $var; (a variable declared, but without a value in a class)

Total Pageviews