开发者

How to compare an array variable and Normal variable using if condition in PHP

I want to compare an array variable and Normal variable using if condition in PHP.. I have an Array VAriable as .$AllowedEnquiryType[$i] and a variabe as $TIntType how to check these to are equal.

My coding is

for($i=1;$i<=$length;$i++)
    {
        if($AllowedEnquiryType[$i]==$TIntType) 
 开发者_如何学编程       {   
             return true;
        }
        else
        {

            return false;
        }
}


Well, if you want to check if $AllowedEnquiryType[$i] and $TIntType are equal, you already wrote what to do :

if ($AllowedEnquiryType[$i] == $TIntType) {
    // those are equal
}


Else, if you want to check if all items of $AllowedEnquiryType are equal to $TIntType, you could do something like this :

$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
}


use in_array

link


Yes, you can use if($AllowedEnquiryType[$i]==$TIntType). What exactly are you asking for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜