Jump to content

Archived

This topic is now archived and is closed to further replies.

JustinK101

Checking Empty/Null Variables

Recommended Posts

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))

Share this post


Link to post
Share on other sites
The only way to check if a variable is empty is to use the [url=http://php.net/empty]empty[/url] function. Empty, NULL and set are all different things.

Share this post


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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.