简体   繁体   English

有条件的PHP帮助

[英]conditional php help

How can I wrap this entire statement below in a condition? 如何在条件下将整个语句包装起来? So If the variable $uprice = 0 then I don't want to to display any of the code below 因此,如果变量$ uprice = 0,那么我不想显示以下任何代码

   <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item-  >getWeeeTaxAppliedAmount()): ?>

   <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?>

  <?php else: ?>
  <?php echo $this->helper('checkout')->formatPrice($_item-    >getCalculationPrice()) ?>
  <?php endif; ?>

This?? 这个??

<?php if ($uprice === 0): ?>    
     <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item-  >getWeeeTaxAppliedAmount()): ?>    
     <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?>    
     <?php else: ?>
     <?php echo $this->helper('checkout')->formatPrice($_item-    >getCalculationPrice()) ?>
     <?php endif; ?>
<?php endif; ?>
if ($uprice == 0){
  if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') 
      && $_item-  >getWeeeTaxAppliedAmount())
  {
    echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()
      +$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition());
  } else {
    echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice())
  }
}

I think your code would be more readable by containing it all in one php block, and as Sarfraz said shouldn't it be as simple as adding a condition around the stuff? 我认为通过将所有代码包含在一个php块中,您的代码将更具可读性,正如Sarfraz所说,它不应该像在内容周围添加条件那样简单吗?

<?php 
if ($uprice == 0)
{
    if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item-  >getWeeeTaxAppliedAmount())
    {
        echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition());
    }
    else 
    {
        echo $this->helper('checkout')->formatPrice($_item-    >getCalculationPrice());
    }
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM