mrpatg
mrpatg

Reputation: 10117

IF statement with AND as well as OR operators PHP

I have the following if statement

if (isset($part->disposition) and ($part->disposition=='attachment'))

Problem is the second part of that statement, i also need to include this;

($part->disposition=='inline')

The statement needs to work if the disposition is attachment or if its inline.

Upvotes: 0

Views: 166

Answers (4)

Sarfraz
Sarfraz

Reputation: 382666

This must help:

if (isset($part->disposition) && ($part->disposition=='attachment' || $part->disposition=='inline'))

Upvotes: 6

Trav L
Trav L

Reputation: 15192

This try (for efficiency):

if (isset($part->disposition))
{
    if($part->disposition=='attachment' || $part->disposition=='inline')
    {
        // perform task
    }
}

Upvotes: 2

VolkerK
VolkerK

Reputation: 96159

In case you may be going to have more than two options in the future you might also be interested in in_array(needle, haystack)

if (
  isset($part->disposition)
  && in_array($part->disposition, array('attachment', 'inline', 'option3', 'option4'))
)

If you want the equivalent of === (strict comparison, instead of == like in your example) set the third parameter of in_array() to true.

Upvotes: 3

Hans Sperker
Hans Sperker

Reputation: 1347

doesn't that work:

if (isset($part->disposition) and (($part->disposition=='attachment') or ($part->disposition=='inline')))

Upvotes: 3

Related Questions