PHP除非字符串匹配怎么办..?

时间:2013-05-04 12:41:30

标签: php

我有这段代码:

<?php unless($category['name'] == "Offer") { ?>
<p>Write this unless category name equal "Offer"</p>
<?php } ?>

我知道这是错误的,你如何在PHP中创建一个除非语句,就像在Rails中一样?

2 个答案:

答案 0 :(得分:3)

使用不等于!=运算符

if($category['name'] != "Offer") {
   //Process here
}

答案 1 :(得分:2)

<?php if ($category['name'] != "Offer") { ?>
<p>Write this unless category name equal "Offer"</p>
<?php } ?>