I agree with Sean but I'll outline what each does in plain English:
if ($variable != NULL) {
$variable
will be NULL
if it hasn't been set. This is practically the same as isset
and the same as the variable being undefined.
if (!empty($variable)) {
Generally, this checks whether $variable
as a string ((string) $variable
) has a strlen
of 0. However true
will make it return false
, as will integers that aren't 0 and empty arrays. For some reason (which I believe to be wrong) $variable = '0';
will return true
.
if ($variable) {
This true/false check acts like (boolean) $variable
- basically whether the variable returns true when converted to a boolean.
One way to think about it is that it acts the same as empty, except returns the opposite value.
For more information on what I mean by (boolean) $variable
(type casting/juggling) see this manual page.
(PHP devs: this is mainly by memory, if I'm wrong here please correct me!)