PHP:我的elseif语句被忽略了 [英] PHP: My elseif statement is ignored
本文介绍了PHP:我的elseif语句被忽略了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 elseif
语句被忽略。 如果
和否则
工作,但 elseif
则不然。
My elseif
statement is being ignored. The if
and else
work but elseif
doesn't.
if ($location === "Canterlot") {
echo "you cannot add a thread here...";
} elseif ($admin === "3") {
echo '<form action="" method="post">
<input type="text" name="thread_name" value="comment">
<textarea name="thread"></textarea>
<input type="submit" value="Comment"/>
</form>';
} else {
echo '<form action="" method="post">
<input type="text" name="thread_name" value="comment">
<textarea name="thread"></textarea>
<input type="submit" value="Comment"/>
</form>';
}
推荐答案
请注意
==运算符只是检查左右值是否相等。但是,===运算符实际上会检查左右值是否相等,并检查它们是否属于同一变量类型。
我认为你有这样的事情:
I think You have some thing like this:
$location = "Canterlot" and $admin ="3";
因此它的第一个条件为真( $ location ==Canterlot
)并且它永远不会检查 else if($ admin ==3)
So it will have first condition true($location == "Canterlot"
) and it never check else if ($admin =="3")
您可以尝试这样的事情:
You can try something like this:
if($location === "Canterlot" && $admin !== "3"){
echo "you cannot add a thread here...";
}else if ($admin === "3"){
echo '<form action="" method="post">
<input type="text" name="thread_name" value="comment">
<textarea name="thread"></textarea>
<input type="submit" value="Comment"/>
</form>';
}else{
echo '<form action="" method="post">
<input type="text" name="thread_name" value="comment">
<textarea name="thread"></textarea>
<input type="submit" value="Comment"/>
</form>';
}
更新:
如果 $ admin
是intteger,那么请检查如下:
If $admin
is intteger then check like this:
if($location === "Canterlot" ){
echo "you cannot add a thread here...";
}else if ($admin == "3"){
echo '<form action="" method="post">
<input type="text" name="thread_name" value="comment">
<textarea name="thread"></textarea>
<input type="submit" value="Comment"/>
</form>';
}else{
echo '<form action="" method="post">
<input type="text" name="thread_name" value="comment">
<textarea name="thread"></textarea>
<input type="submit" value="Comment"/>
</form>';
}
这篇关于PHP:我的elseif语句被忽略了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文