我想检查“$v”和“$formats2”是否相等。但它给出了错误信息
Warning: strcmp() expects parameter 2 to be string, array given in C:\xampp\htdocs\playit2\product.php on line 312
这是我的 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>
最佳答案
您将 implode
误输入为 explode
。后者接受一个字符串并生成一个数组。你可能想要相反的东西。 UPD:哦,你已经有了一个字符串。然后简单地按原样使用它:
- $formats2 = explode(";", $jfeta2['formats']);
+ $formats2 = $jfeta2['formats'];
希望对您有所帮助。
关于php - php中如何比较两个字符串是否相等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27101986/