Jump to content

question about similar variable values


vijdev

Recommended Posts

There's a table in the documentation that shows what is considered to be 'empty' - http://php.net/manual/en/types.comparisons.php

 

You could also just test each of those values using some code to see for yourself.

Hi there Vijdev,

$variable=""; //Setting var as empty or setting it for later, quotes mean string
$variable=0//numerical value or can be boolean
$variable=NULL//Same as the top one, but useful for passing into functions as an optional paramter

 

and

and which of the above will satisfy

if(empty($variable))

{

echo "blah!";

}

 

The top one, and if nothing is sent into the last one, that can be construed as empty/not set.  Bearing in mind that isset() and empty() have similar uses - BUT empty checks to see if there is any value in the variable, this is useful to check session/cookie data etc.

 

Hope that helps a little.

 

Cheers,

Rw

Archived

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

×
×
  • Create New...

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.