在PHP'中检查多个条件;如果';陈述

在PHP'中检查多个条件;如果';陈述,php,opencart,Php,Opencart,我想实现的是,如果产品id是53或50或43,那么…同样的事情..但我不确定这样是否正确您可以将产品id存储在数组中,然后使用以下功能: if($this->request->get['product_id'] == (53 || 52 || 43)){ if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product2.tpl'))

我想实现的是,如果产品id是
53
50
43
,那么…同样的事情..但我不确定这样是否正确

您可以将产品id存储在数组中,然后使用以下功能:

if($this->request->get['product_id'] == (53 || 52 || 43)){
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product2.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/product/product2.tpl';
    } else {
        $this->template = 'default/template/product/product2.tpl';
    }
} else{
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/product/product.tpl';
    } else {
        $this->template = 'default/template/product/product.tpl';
    }
}
数组中的
-检查数组中是否存在值

应该是:

if($this->request->get['product_id'] == (53 || 52 || 43)){

您还可以在_数组中使用
,这将使您的代码看起来更干净,但速度可能较慢。蒂姆·库珀给出了这方面的示例代码。

这是最好的解决方案,@Tom应该坚持这一个。不知怎么的,这一个似乎不起作用:S我完全更改了它,它显示了错误它现在起作用了,额外的)最后需要,谢谢大家:)是的,因为它在一秒钟内引起了注意:)
if($this->request->get['product_id'] == 53
   || $this->request->get['product_id'] == 52
   || $this->request->get['product_id'] == 43) {
if($this->request->get['product_id'] == 53
   || $this->request->get['product_id'] == 52
   || $this->request->get['product_id'] == 43) {
$prodId = $this->request->get['product_id'];
if($prodId == 53 || $prodId == 52 || $prodId == 43){
....