codeigniter 在本地服务器上工作但是:语法错误,模型中出现意外的“[”,期望“)”

codeigniter working on local server but : syntax error, unexpected '[', expecting ')' in model

我正在尝试在 000webhost 服务器上上传我的 codeigniter 网站。但它给我一个语法错误

syntax error, unexpected '[', expecting ')' in /home/a4703701/public_html/application/controllers/update.php

但它在本地主机上工作正常。

错误在模型中 我的模型是

public function user($id=NULL)
    {
       if($id=='')
         {
            $q  = $this->db->get('user');
            if($q->num_rows()>0)
            {
                return $q;
            }
         }
      else 
         {
            $q  = $this->db->get_where('user',['id'=>$id]);
            if($q->num_rows()>0)
            {
                return $q->row();
            }
         }
    }

知道如何消除这个错误吗?

您几乎可以肯定不是 运行 PHP 5.4 或更高版本,但正在尝试使用仅在这些版本中可用的语法。

['id'=>$id]

是 shorthand 数组语法,在 PHP 5.4 中引入。您需要将其替换为:

array('id'=>$id)

向后兼容之前的 PHP 版本。