如果有条件,简化PHP乘法

鲨鱼

我想知道有什么方法可以使此代码更微妙吗?

前任

 public function hookDisplayHeader()
{
    if(Tools::getValue('controller')=='index'){
        $this->context->controller->addCSS(($this->_path).'something.css', 'all');
    }
    if(Tools::getValue('controller')=='cms'){
        $this->context->controller->addCSS(($this->_path).'something.css', 'all');
    }
    if(Tools::getValue('controller')=='product'){
        $this->context->controller->addCSS(($this->_path).'something.css', 'all');
    }
    if(Tools::getValue('controller')=='category'){
        $this->context->controller->addCSS(($this->_path).'something.css', 'all');
    }

}

简单

 public function hookDisplayHeader()
     {
         if(Tools::getValue('controller')=='index AND product AND cms AND category'){
        $this->context->controller->addCSS(($this->_path).'something.css', 'all');
         }
     }

此代码不起作用:(

摇篮

使用 in_array();

public function hookDisplayHeader()
{
    $values = array('index','cms','product','category');
    if(in_array(Tools::getValue('controller'), $values)){
        $this->context->controller->addCSS(($this->_path).'something.css', 'all');
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章