PHP比较elseif忽略if

时间:2014-02-03 02:54:08

标签: php if-statement comparison

出于某种原因,我无法让这个工作,如果还有更好的方法,请分享:)

    <?php $or->billing['street_address'] = "123 Nowhere St";
      $or->billing['city'] = "Somewhere"; 
      $or->billing['postcode'] = "92702";
      $or->billing['state'] = "CA";
      $or->shipping['street_address'] = "123 Nowhere St";
      $or->shipping['city'] = "Somewhere"; 
      $or->shipping['postcode'] = "92702";
      $or->shipping['state'] = "CA"; 
      ?>

Billing: <a href="...&street=<?php echo $or->billing['street_address']?>&where=<?php echo $or->billing['postcode']?>"> <?php echo $or->billing['street_address'].', ' .$or->billing['city'].', ' .$or->billing['state']. ' ' .$or->billing['postcode']; ?></a>

Shipping: <a href="...&street=<?php echo $or->shipping['street_address']?>&where=<?php echo $or->shipping['postcode']?>"> <?php echo $or->shipping['street_address'].', ' .$or->shipping['city'].', ' .$or->shipping['state']. ' ' .$or->shipping['postcode']; ?></a>

<?php 
if ($or->billing['street_adddress'] == $or->shipping['street_address'] )  { 
echo "Billing/Shipping Match";
} elseif ($or->billing['postcode'] == $or->shipping['postcode']) {
echo "ZIP codes Match";
} else 
{
echo "Different Billing/Shipping ZIP codes";
}

?>

不确定为什么它不会认识到应该回应的是“结算/运输匹配”,而不是“邮政编码匹配”。您可以提供的任何帮助将非常感谢!

我已经尝试添加类似

的内容
&& ($or->billing['street_adddress'] != $or->shipping['street_address'])

到了elseif,它仍然无效(from here

有人有什么想法吗?哦,我编辑了URL,所以它更干净但它链接到whitepages.com。只是想检查一下客户的账单和送货地址是否匹配。

1 个答案:

答案 0 :(得分:3)

你在street_address中有一个额外的'd'。

if ($or->billing['street_adddress'] == $or->shipping['street_address'] )
                            ^

显示Undefined index: street_adddress