[英]How to compare an array variable and Normal variable using if condition in PHP
我想在PHP中使用if條件比較數組變量和Normal變量。我有一個數組VAriable為。$ AllowedEnquiryType [$ i]和一個變量為$ TIntType如何檢查這些是相等的。
我的編碼是
for($i=1;$i<=$length;$i++)
{
if($AllowedEnquiryType[$i]==$TIntType)
{
return true;
}
else
{
return false;
}
}
好吧,如果你想檢查$AllowedEnquiryType[$i]
和$TIntType
是否相等,你已經寫了怎么做:
if ($AllowedEnquiryType[$i] == $TIntType) {
// those are equal
}
另外,如果你想檢查$AllowedEnquiryType
所有項$AllowedEnquiryType
都等於$TIntType
,你可以這樣做:
$allEqual = true;
for($i=1;$i<=$length;$i++) {
if ($AllowedEnquiryType[$i] != $TIntType) {
$allEqual = false;
break; // no need to check the other items
}
}
if ($allEqual) {
// all items in $AllowedEnquiryType are equal to $TIntType
}
使用in_array
是的,您可以使用if($AllowedEnquiryType[$i]==$TIntType)
。 你究竟想要什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.