开发者

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 o开发者_JS百科r if its inline.


This must help:

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


doesn't that work:

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


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.


This try (for efficiency):

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜