Place an IF with various conditions

Asked

Viewed 873 times

0

I want to put an If with various conditions.

if ($row[??] != '' or NULL or 0000-00-00 )

Currently I have like this but I want to put two more Row. I have to create more if or I can add in that If?

  • You really have to make a condition x != y for each or

  • On the answers below, just watch out for the operators' precedence. There are differences between and, or and &&, || See test manual: http://php.net/manual/en/language.operators.precedence.php#117390

1 answer

6


The problem with your if is that the or are comparing nothing to nothing.

You need to compare again to something ($row[??] in your case):

if ($row['xpto'] != '' and $row['xpto'] != NULL and $row['xpto'] != '0000-00-00' )

Improving your code, to check if the variable is empty ('' or NULL), use the function empty.

if (!empty($row['xpto']) and $row['xpto'] != '0000-00-00' )

PS.: Don’t forget the quotation marks on the date! ('0000-00-00')

PS2.: Analyzing better, how are you verifying what is different, so the correct operator to use is and (or &&)

  • 1

    It wants different from empty so it should use ! Empty

  • Obg. corrected.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.