如何比较php中两个字符串的相等性?

如何比较php中两个字符串的相等性?,php,html,css,Php,Html,Css,我想检查$v和$formats2的相等性。但它给出了错误信息 警告:strcmp希望参数2是字符串,数组在第312行的C:\xampp\htdocs\playit2\product.php中给出 这是我的HTML代码 $jsqla = mysql_query("select * from products where id='$product_id'") or die(mysql_error()); $jfeta = mysql_fetch_assoc($jsqla); $formats =

我想检查$v和$formats2的相等性。但它给出了错误信息

警告:strcmp希望参数2是字符串,数组在第312行的C:\xampp\htdocs\playit2\product.php中给出

这是我的HTML代码

$jsqla = mysql_query("select * from products where id='$product_id'") or die(mysql_error());

$jfeta = mysql_fetch_assoc($jsqla);

$formats = explode(";", $jfeta['formats']);

$jsqla2 = mysql_query("select formats from request_list where id='$product_id'") or die(mysql_error());

$jfeta2 = mysql_fetch_assoc($jsqla2);

$formats2 = explode(";", $jfeta2['formats']);

<div class="">
    <?php if($formats2 != "") { ?>
        <?php foreach($formats as $v){ ?>
            <label style="line-height: 1.25em;display: block;width: 100px;margin-right: 10px;float: left;">                         
                <div id="format-id_<?php echo $v?>" <?php if (strcmp($v, $formats2) === 0) { ?> style="border: 1px solid;border-radius: 9px;text-align: center;padding-top: 10px;padding-bottom:10px;padding-left: 3px;padding-right: 3px;border-color: #cccccc;font-family: 'SSemibold'; font-size: 13px; color: #44b7da; background-color: #cccccc;" <?php } else { ?> style="border: 1px solid;border-radius: 9px;text-align: center;padding-top: 10px;padding-bottom:10px;padding-left: 3px;padding-right: 3px;border-color: #cccccc;font-family: 'SSemibold'; font-size: 13px; color: #44b7da;" <?php } ?>>                                
                    <input class="format_cheks" type="radio" value="<?php echo $v; ?>" name="abc" style="visibility:hidden;" id="<?php echo $v ?>" onClick="changeColour(this)"/>
                        <span style="margin:-17px auto auto 0px;display:block;"><?php echo $v; ?></span>                            
                </div>                      
            </label>
        <?php } ?>
    <?php } else { ?>
        <?php foreach($formats as $v){ ?>
            <label style="line-height: 1.25em;display: block;width: 100px;margin-right: 10px;float: left;">                         
                <div id="format-id_<?php echo $v?>" style="border: 1px solid;border-radius: 9px;text-align: center;padding-top: 10px;padding-bottom:10px;padding-left: 3px;padding-right: 3px;border-color: #cccccc;font-family: 'SSemibold'; font-size: 13px; color: #44b7da;">                                
                    <input class="format_cheks" type="radio" value="<?php echo $v; ?>" name="abc" style="visibility:hidden;" id="<?php echo $v ?>" onClick="changeColour(this)"/>
                        <span style="margin:-17px auto auto 0px;display:block;"><?php echo $v; ?></span>                            
                </div>                      
            </label>
        <?php } ?>
    <?php } ?>
</div>
您输入的错误“内爆”为“爆炸”。后者接受一个字符串并生成一个数组。你可能想要相反的结果。UPD:哦,你已经有一根绳子了。然后简单地按原样使用:

- $formats2 = explode(";", $jfeta2['formats']);
+ $formats2 = $jfeta2['formats'];
希望有帮助。

您应该传递密钥,因为爆炸后它将包含一个数组

strcmp($v, $formats2[key])

关于这个错误,你不明白的是什么?这很直截了当。为什么人们会对这些问题投赞成票呢?如果你能描述一下你想做什么,你会更容易得到帮助。根据我所看到的,它没有多大意义。不过我不这么认为,因为它已经是一个字符串了。
You also use 
if( $val1 === $val2){
   //true part . this === strictly check 
}