Search code examples
phpphp-5.3

if and isset which one to use


Possible Duplicate:
Why do I need the isset() function in php?

whats the difference if I say

if($value){}

vs

if (isset($value)){}

I had been asked to change if($value) to isset($value)

thanks


Solution

  • PHP generates a warning (Undefined variable) when you access an undefined variable using if ($value)

    Use if (isset($value)) to test if a variable has been declared.

    Use if ($value) if you know the variable has been declared, and you want to evaluate the contents as boolean.