【问题标题】:How Can I Combine two Arguments Using If Statements in PHP如何在 PHP 中使用 If 语句组合两个参数
【发布时间】:2014-07-02 20:07:49
【问题描述】:

我真的需要你的帮助。我想知道如何在一个 if 语句中使用两个大于(>)和小于(

<?php

$value1="7";
if($value1<78);
if($value1>7);
{print"Yes, the answer is above 7 but below 78";} 

else 

{print"that's not correct";}


?>

任何帮助将不胜感激,谢谢。

【问题讨论】:

标签: php if-statement default-arguments


【解决方案1】:

使用&amp;&amp;:

if($value1 < 78 && $value1 > 7){
    print"Yes, the answer is above 7 but below 78";
} 
else {
    print"that's not correct";
}

请参阅:Control StructuresLogical Operators

【讨论】:

  • 感谢约翰,它成功了!!。抱歉,我暂时无法投票,积分不够。
【解决方案2】:
<?php
$value1="7";
if($value1<78 && $value1>7)
{
    print "Yes, the answer is above 7 but below 78";
} 
else 
{
    print"that's not correct";
}
?>

【讨论】:

    【解决方案3】:

    正如其他人所提到的,使用 PHPs &amp;&amp; (and) 来组合逻辑。

    作为此处列出的 if/else 方法的替代方法,您可以使用 PHP 的 ternary operators

    类似这样的:

    echo ($value1<78 && $value1>7)
        ? "Yes, the answer is above 7 but below 78."
        : "That's not correct";
    

    【讨论】:

      猜你喜欢
      • 2012-08-01
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多