错误:间接修改重载属性

时间:2015-06-27 18:04:58

标签: php laravel laravel-4 laravel-5

我有一个数组看起来像:

{
  "1": {
    "id": "1",
    "user_id": "9",
    "post_id": "61",
    "parent_id": "0",
    "message": "Level 0.",
    "created_at": "2015-06-27 12:46:18",
    "updated_at": "-0001-11-30 00:00:00",
    "children": []
  },
  "2": {
    "id": "2",
    "user_id": "9",
    "post_id": "61",
    "parent_id": "1",
    "message": "Level 1.",
    "created_at": "2015-06-27 12:46:22",
    "updated_at": "-0001-11-30 00:00:00",
    "children": []
  }
}

然后我有一个看起来像这样的循环:

foreach ($tree as $key => &$value)
{
    if ($value->parent_id != 0)
    {
        $tree[$value->parent_id]->children[] = &$value;
    }
}

然而,这会返回以下错误:

  

间接修改重载属性Comment :: $ children无效

为什么呢?我该如何解决这个问题?

0 个答案:

没有答案