Page 1 of 1
Difference between if($example), if(!empty($example))?
Posted: Sat Mar 12, 2011 3:27 am
by meee
What makes a difference between if(!empty($example)) and if($example)?
I don't find any example when this would print a different result.
Re: Difference between if($example), if(!empty($example))?
Posted: Sat Mar 12, 2011 12:23 pm
by Darhazer
They won't print different result, but the first one is more readable, especially if you are dealing with array. If the variable is not an array, there is no difference (and again, the difference would be just in the readability).
Other than that, the only difference is that empty() won't triger notice if the variable is not defined.
Re: Difference between if($example), if(!empty($example))?
Posted: Sat Mar 12, 2011 5:20 pm
by meee
Now I see about the trigger notice. So I assume that recommended use is isset, right?