Jump to content


Photo

Checking Empty/Null Variables


  • Please log in to reply
2 replies to this topic

#1 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 27 September 2006 - 10:36 PM

Hello all, I have been programming in PHP for a while, but never quite learned the best/effective way to check if a variable is empty?

What is the best method to use?

if(!isset($var))
if($var == null)
if($var == "")
if(empty($var))
if(is_null($var))


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 27 September 2006 - 10:41 PM

The only way to check if a variable is empty is to use the empty function. Empty, NULL and set are all different things.

#3 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 27 September 2006 - 10:46 PM

Yeah most of the time I am checking strings from FORMS, i.e. textfields and pulldown menus. Appears empty() is the one to use.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users