语法错误,意外' [',期待')' php错误消息

时间:2017-09-25 21:40:47

标签: php oop

我只是不明白为什么会收到这条消息:

解析错误:语法错误,意外情况' [',期待')'第11行

在此档案中:

    <?php 
class Telegram
{   
    protected $notice = array();
    private $db;
    public function __construct()
    {
        $this->db = new Connection();
        $this->db = $this->db->dbConnect();
    }
    public function AddNew($token,$cat,$ads[$i],$key[$j])
    {
        if(!empty($token)&&!empty($cat)&&!empty($ads))
        {
            $new = $this->con->prepare("INSERT INTO channels (token_number, category_name, ads_set, keyboard_status) VALUES (?, ?, ".$ads[$i].", ".$key[$i].")");
            $new->bindParam(1,$token);
            $new->bindParam(2,$cat);
            $new->bindParam(3,$ads);
            $new->bindParam(4,$key);
            $new->execute();
            $notice['success_message'] = "New Telegram Channel was successfully added";
            return $this->notice;

        }
    }
    public function getNotice()
    {
        return $this->notice;
    }
}
?>

第11行是这样的:

public function AddNew($token,$cat,$ads[$i],$key[$j])

3 个答案:

答案 0 :(得分:2)

您不能在函数参数中使用数组索引。

public function AddNew($token,$cat,$ads,$key)
{

}

答案 1 :(得分:0)

尝试在参数中传递数组(如果要访问数组中的特定数据,则单独传递$ i变量):)

答案 2 :(得分:0)

试试这个你可以像这样传递数组和键

public function AddNew($token,$cat,$ads,$key)
{
    if(!empty($token)&&!empty($cat)&&!empty($ads))
    {
        $new = $this->con->prepare("INSERT INTO channels (token_number, category_name, ads_set, keyboard_status) VALUES (?, ?, ".$ads[$i].", ".$key[$i].")");
        $new->bindParam(1,$token);
        $new->bindParam(2,$cat);
        $new->bindParam(3,$ads);
        $new->bindParam(4,$key);
        $new->execute();
        $notice['success_message'] = "New Telegram Channel was successfully added";
        return $this->notice;

    }
}