如何在同一个if语句中有多个条件? [英] How to have multiple conditions on the same if statement?

查看:130
本文介绍了如何在同一个if语句中有多个条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<强>可能重复:结果,
php if if statement with multiple conditions





$style = get_option('background_style');
if ($style == "option1") {
    echo '<div class="background-style1">';
} 

如果我想让选项1回音,这就是我所拥有的div类.background-style1,但我想知道如何在选项1之后列出更多选项。

This is what I've got if I want "option 1" to echo the div class .background-style1, but I'm wondering how I could list more options after "option 1".

我试过这个:

if ($style == "option1", "option2", "option3")

但它不起作用。这样做的正确方法是什么?

But it doesn't work. What is the right way of doing this?

推荐答案

if ($style == 'option1' or $style == 'option2' or $style == 'option3') {
    // do something...
}

这是在if语句中包含多个条件的最基本方法,您也可以使用其他逻辑运算符。欲了解更多信息,请参阅:

This is the most basic way to include multiple conditions in an if statement, you can also use other logical operators. for more info see here:

http://php.net/manual/en/language.operators.logical.php

这篇关于如何在同一个if语句中有多个条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆