如果语句不能正常工作?
我正在运行 wordpress,这是为了搜索。基本上,我将根据选中的复选框设置帖子类型(如果选中它们,则传递值 1)。
当搜索我的网址包含 job=1&opportunity=1&resource=1
时,并且我尝试了带引号和不带引号的值,它不会在以下位置输出 HELLO
全部。
$job = wp_specialchars(stripslashes($_GET["job"]), 1);
$opportunity = wp_specialchars(stripslashes($_GET["opportunity"]), 1);
$resource = wp_specialchars(stripslashes($_GET["resource"]), 1);
if(($job == '1') && ($opportunity == '1') && (resource == '1')){
echo 'HELLO';
}elseif($job == '1' && $opportunity == '1'){
}elseif($job == '1' && resource == '1'){
}elseif($opportunity == '1' && resource == '1'){
}elseif($job == '1'){
}elseif($opportunity == '1'){
}elseif($resource == '1'){
}
另外,如果有人可以使它成为一个更短/更语义的 if 语句,无论如何,那就去做吧。
I'm running wordpress and this is to search. Basically, I'm going to set the post type based on what checkboxes are selected (if they're checked, they pass a value of 1).
When searching my URL includes job=1&opportunity=1&resource=1
, and I've tried the values both with and without quotes, it will not output HELLO
at all.
$job = wp_specialchars(stripslashes($_GET["job"]), 1);
$opportunity = wp_specialchars(stripslashes($_GET["opportunity"]), 1);
$resource = wp_specialchars(stripslashes($_GET["resource"]), 1);
if(($job == '1') && ($opportunity == '1') && (resource == '1')){
echo 'HELLO';
}elseif($job == '1' && $opportunity == '1'){
}elseif($job == '1' && resource == '1'){
}elseif($opportunity == '1' && resource == '1'){
}elseif($job == '1'){
}elseif($opportunity == '1'){
}elseif($resource == '1'){
}
Also, if anyone can make this a shorter/more semantic if statement, by all means, go for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果粘贴了上面的代码,请查看以下内容:
您可能想尝试这些并再次执行(尽管上面的代码可能会出现错误)。
If above code is pasted then look at the following:
You might want to try these and execute again (although errors might be expected with the above code).
您似乎有一个拼写错误:
资源
缺少$
。确保您已打开错误报告 (
error_reporting(E_ALL);
- 此特定问题将引发E_NOTICE
级别警告。You seem to have a typo:
$
is missing forresource
.Make sure you have error reporting turned on (
error_reporting(E_ALL);
- this particular issue will throw aE_NOTICE
level warning.