If statement 分析错误:语法错误,意外';如果';(T#u IF),预期为';)';在第29行的D:\xampp\htdocs\ramesh\wmw\catalog\controller\product\sub_category.php中

If statement 分析错误:语法错误,意外';如果';(T#u IF),预期为';)';在第29行的D:\xampp\htdocs\ramesh\wmw\catalog\controller\product\sub_category.php中,if-statement,opencart,href,If Statement,Opencart,Href,我在尝试为不同的href运行if语句时收到此错误 分析错误:语法错误,第29行的D:\xampp\htdocs\ramesh\wmw\catalog\controller\product\sub_category.php中出现意外的“if”(T_if),应为“') sub_category.php foreach ($category_info as $result) { $data['categories'][] = array( 'name' => $r

我在尝试为不同的
href
运行
if语句时收到此错误

分析错误:语法错误,第29行的D:\xampp\htdocs\ramesh\wmw\catalog\controller\product\sub_category.php中出现意外的“if”(T_if),应为“')

sub_category.php

foreach ($category_info as $result) {
        $data['categories'][] = array(
        'name' => $result['name'],
        'parent_id' => $result['parent_id'],
        'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), this->config->get('config_image_category_height')),
        'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
        /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
        'href' => $this->url->link('product/sub_category')*/
        if($result['category_id']==24)
        {
            'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
    }
    elseif
    {
            /*some code for href*/
        }

      );
}

最后,我得到了以下代码运行良好的答案

 foreach ($category_info as $result) {
 if($result['category_id']==24)
 {
    $link1 = $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id']);
 }
else
{
    $link1 = $this->url->link($_SERVER["REQUEST_URI"]);
}
$data['categories'][] = array(
    'name' => $result['name'],
    'parent_id' => $result['parent_id'],
    'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
    /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
    'href' => $this->url->link('product/sub_category')
    'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])*/
    'href' => $link1
);

}您的代码语法错误。数组中不允许使用If else条件

请用以下代码替换您的代码,错误将得到解决-

foreach($类别信息作为$结果){ $href=''


}

请检查。谢谢@PhilipZou的重播。对不起,我不明白。请用我的代码告诉我。很容易得到结果感谢您的replay@Knowband插件,但我的代码运行良好
    if ($result['category_id']==24) {
        $href = $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id']);
    } else {
        /*some code for href*/
    }

    $data['categories'][] = array(
    'name' => $result['name'],
    'parent_id' => $result['parent_id'],
    'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
    /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
    'href' => $this->url->link('product/sub_category')*/        
    'href' => $href    

  );