如果声明在我的代码中不起作用。 变量未经测试[关闭]
问题描述:
In PHP I have used:
if($a=="no" or $curriculum=="yes")
Do you find anything wrong with that if
statement?
It displays the contents of if
even when $a = yes
and $curriculum = no
..
I have done enough checks to check whether the variables have the correct value..
Please help!!
在PHP中,我使用过: p>
if($ a ==“no”或$ curriculum ==“yes”)
code> pre>
您是否发现 if code>语句有什么问题? p>
它显示 if code>的内容,即使 $ a = yes code>和 $ curriculum = no code> .. \ 我已经做了足够的检查来检查变量是否具有正确的值..
请帮助!! p>
div>
答
you can try this
if($a=="no" || $curriculum=="yes")
答
Alright, here are some tests.
Your if statement is fine ( or
works as well as ||
does in this case )
$a = 'abc';
$curriculum = 'abc';
if($a == "no" or $curriculum == "yes") {
echo 'Either $a equals "no" or $curriculum equals "yes"<br>'.PHP_EOL;
} else {
echo 'Neither $a equals "no" nor does $curriculum equal "yes"<br>'.PHP_EOL;
}
$a = 'no';
$curriculum = 'abc';
if($a == "no" or $curriculum == "yes") {
echo 'Either $a equals "no" or $curriculum equals "yes"<br>'.PHP_EOL;
} else {
echo 'Neither $a equals "no" nor does $curriculum equal "yes"<br>'.PHP_EOL;
}
$a = 'abc';
$curriculum = 'yes';
if($a == "no" or $curriculum == "yes") {
echo 'Either $a equals "no" or $curriculum equals "yes"<br>'.PHP_EOL;
} else {
echo 'Neither $a equals "no" nor does $curriculum equal "yes"<br>'.PHP_EOL;
}
These result in:
Neither $a equals "no" nor does $curriculum equal "yes"
Either $a equals "no" or $curriculum equals "yes"
Either $a equals "no" or $curriculum equals "yes"
Please do a var_dump of both variables right before the if statement and show us the results:
var_dump($a);
var_dump($curriculum);
if($a == "no" or $curriculum == "yes") {