我遇到了一个客户端代码段。我想说如果不,那么这样做。因此,Array中的所有项都不起作用。我不知道为什么它仍然存在!
$StuddedListArray = array("563_black","564_white","565_black","578_turq","570_black","581_blush","584_white","578_black","570_grey","585_blush","567_black","564_white","580_blush","591_black","578_blush","589_black");
if(!$promocode="gcnow20" && in_array($newitemID, $StuddedListArray)){
// do nothing
}else {
$promocode_validate_check = $_POST['promocode'];
}
答案 0 :(得分:2)
!$promocode="gcnow20"
始终为false ..如果要检查值是否相等,则必须使用!$promocode=="gcnow20"
同样由@Vilx-
评论!$promocode=="gcnow20"
可以写成:
$promocode!="gcnow20"
答案 1 :(得分:1)
也许是因为你打算写
$promocode=="gcnow20"
而不是
$promocode="gcnow20"
答案 2 :(得分:1)
!$promocode="gcnow20"
将始终返回false。
为变量赋值
使用
if (!($promocode="gcnow20" && in_array($newitemID, $StuddedListArray))){
答案 3 :(得分:1)
if (!($promocode == 'gcnow20' && in_array(...
是什么意思? promocode
在哪里设置?您也可以写if ($promocode != 'gcnow20' ...
答案 4 :(得分:1)
如果我理解得很好,你想检查$ promocode 不同而不是“gcnow20”,$ itemID是不是在数组中?然后:
$StuddedListArray = array("563_black","564_white","565_black","578_turq","570_black","581_blush","584_white","578_black","570_grey","585_blush","567_black","564_white","580_blush","591_black","578_blush","589_black");
if($promocode !="gcnow20" && !in_array($newitemID, $StuddedListArray)){
// do nothing
}else {
$promocode_validate_check = $_POST['promocode'];
}