【问题标题】:Warning: Illegal offset type in警告:非法偏移类型
【发布时间】:2015-03-26 23:54:31
【问题描述】:

我对这段代码有一些问题。警告:第 22 行中的非法偏移类型

$this->word[$kata][]=array($i,$j);

完整代码如下

private $jmldoc = 0; private $word = array();

public function getIndex($D) {
    $this->jmldoc = count($D);

    for($i=0; $i<$this->jmldoc; $i++) {
        $pp = new prePro($D[$i]);
        $kata = $pp->tokenize();
        $n = count($kata); 
        for($j=0; $j<$n; $j++) {
            $this->word[$kata]=array($i,$j);
        }
    }
}

你能帮我解决它吗?

【问题讨论】:

    标签: php arrays class offset


    【解决方案1】:

    你传递的是一个数组,而不是一个字符串/整数索引到你的 $this->word。

        //I suppose from the context of your code that $kata is an array also
        //so if that's true, it can't be used as an index
        $this->word[$kata][]=array($i,$j);
    

    请记住 $this->word 是一个数组。因此,您的程序逻辑可能有问题。要解决此问题,请使用整数或字符串来访问数组的元素。

    【讨论】:

    • 当我意识到 SimpleXML 总是返回对象而不是字符串时遇到了这个问题...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 2015-03-07
    • 2021-09-30
    • 2013-09-13
    相关资源
    最近更新 更多