Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
';如果';PHP中的语句_Php_Conditional Operator - Fatal编程技术网

';如果';PHP中的语句

';如果';PHP中的语句,php,conditional-operator,Php,Conditional Operator,我不确定我的IF语句是否正确- 如果变量$answer不是'4'或'four',我希望代码结束 如果变量$answer等于4或4,程序将继续处理代码 感谢您的帮助 谢谢 if( ! in_array($answer, array(4, 'four'))) { //if answer is not in an array containing either 4 or four then.. echo "You have entered the securit

我不确定我的IF语句是否正确-

  • 如果变量
    $answer
    不是
    '4'
    'four'
    ,我希望代码结束

  • 如果变量
    $answer
    等于4或4,程序将继续处理代码

感谢您的帮助

谢谢

if( ! in_array($answer, array(4, 'four')))
{   
       //if answer is not in an array containing either 4 or four then..
        echo "You have entered the security question incorrectly. Your request will NOT be processed";
        exit();
}
else
{
    if ($from != "")
    {
            //test send mail to Melanie 
            mail($to, $subject, $contents, $from_header);

            // redirect back to url visitor came from
            $display_blockmsg = "Thank you, <b>$_POST[title] $_POST[firstname] $_POST[lastname]</b>, <br>
                                Your contact form details have been sent to us <br>
                                Your contact details are:<br><br>
                                <b>Address:</b> $_POST[address1] 
                                $_POST[address2],<br>
                                <b>City:</b> $_POST[city]<br>
                                <b>County:</b> $_POST[county]<br>
                                <b>Postcode:</b> $_POST[postcode]<br>
                                <b>Country:</b> $_POST[country]<br>
                                <b>Telephone:</b> $_POST[telephone]<br>
                                <b>email:</b> $_POST[from]<br><br>";        
  }
  else      
  {     
      $display_blockmsg = "<center><b>The email field</b> is empty. Please go back and complete this field.</center>"; 
  }
} //end of first else ...if
if(!in_数组($answer,数组(4,'four'))
{   
//如果答案不在包含4或4的数组中,则。。
echo“您输入的安全问题不正确。您的请求将不会得到处理”;
退出();
}
其他的
{
如果($from!=“”)
{
//试着给梅勒妮发邮件
邮件($to、$subject、$contents、$from_header);
//重定向回访问者来自的url
$display\u blockmsg=“谢谢,$\u POST[title]$\u POST[firstname]$\u POST[lastname],
您的联系方式详情已发送给我们
您的联系方式是:

地址:$\邮递[地址1] $\邮政[address2],
城市:$\u邮政[城市]
县:$\u邮政[县]
邮政编码:$\u邮政[邮政编码]
国家:$\u邮政[国家]
电话:$\u邮政[电话]
电子邮件:$_POST[from]

“; } 其他的 { $display\u blockmsg=“电子邮件字段为空。请返回并填写此字段。”; } }//第一个else的结尾…如果
试试这个

if(!in_数组($answer,array('4','four'))
而不是
if(!in_数组($answer,array('4','four'))

$answer是一个字符串,在数组中是一个数字(整数)

所以最好使用


if($answer!=4&&$answer!='four')
if控件看起来像

if(// condition is true) { 
  $that
} elseif (// another condition is true ) { 
  // anotherthing 
} else { 
  // somethingelse 
}
如果退出If语句,则不会执行其余代码


本手册非常有用-。

对于两个选项,您不需要创建阵列和使用阵列选项。只要用这个:

if ($answer != 4 && $answer != 'four')

嗨,谢谢,到目前为止,我的支架都在嘴上了?真倒霉。我不能重新编写代码?请帮忙