有人帮助我,请PHP如果其他条件
<?php if ($_POST['jobs'] == 6 || 7 || 8 || 9 && $_POST['sex'] = 'L') {*true statement*} ?>
它是正确的? CMIIW。 有人请解释如何写数组条件。谢谢
有人帮助我,请PHP如果其他条件
<?php if ($_POST['jobs'] == 6 || 7 || 8 || 9 && $_POST['sex'] = 'L') {*true statement*} ?>
它是正确的? CMIIW。 有人请解释如何写数组条件。谢谢
我建议你看看in_array函数。
$jobs = array('6', '7', '8', '9');
if (in_array($_POST['jobs'], $jobs) && $_POST['sex'] == 'L')
{
//Do something.
}
哇,谢谢你的工作 – 2014-10-17 06:33:28
尝试这种方式
<?php
$string="6 || 7 || 8 || 9";
$newarray=explode('||',$string); // $newarray is like array('6', '7', '8', '9');
if (in_array($_POST['jobs'],$newarray) && $_POST['sex'] == 'L') {*true statement*}
?>
如果$ _ POST [ '工作']只包含一个值,使阵列的所有预期的结果。之后,您可以使用in_array函数来检查数组中是否包含该值。
$resultArray = array('6', '7', '7', '8');
if (in_array($_POST['jobs'], $resultArray) && $_POST['sex'] == 'L')
{
//true condition
}
试试这个你有||
<?php if ($_POST['jobs'] == 6 || $_POST['jobs'] == 7 || $_POST['jobs'] ==8
|| $_POST['jobs'] ==9 && $_POST['sex'] = 'L') {}
?>
您使用一个等号,而不是两个在这里,当你每次都使用给值:
$_POST['sex'] = 'L'
,使程序总是看到条件真实并将$ _POST ['sex']设置为'L'。
我这样做:
$jobs = array(6, 7, 8, 9);
if ((in_array($_POST['jobs'], $jobs) && (strcmp($_POST['sex'], 'L') == 0)) {
//Do super cool stuff
}
其价值得到$ _ POST [ '工作'] – 2014-10-17 06:17:08
使用in_array功能。 – 2014-10-17 06:17:10
'$ _POST ['sex'] ='L''我假设你的意思是双等于? – MLeFevre 2014-10-17 06:21:55