我试图遍历一个称为items的对象属性,该对象属性包含一个数组:
foreach ($this->footerList->items as $item)
当我执行该语句时,我收到一条错误消息-即使试图获取非对象的属性,
var_dump($this->footerList)
显示$this-> footerList确实包含项数组.
object(FooterModel)#13 (1)
{
["items"]=> array(3)
{
[0]=> array(5)
{
["id"]=> string(20) "terms-and-conditions"
["title"]=> string(20) "Terms and Conditions"
["url"]=> string(23) "home/termsandconditions"
["label"]=> string(20) "Terms and Conditions"
["authenticatedOnly"]=> string(5) "false"
}
[1]=> array(5)
{
["id"]=> string(14) "privacy-policy"
["title"]=> string(14) "Privacy Policy"
["url"]=> string(18) "home/privacypolicy"
["label"]=> string(14) "Privacy Policy"
["authenticatedOnly"]=> string(5) "false"
}
}
}
有人可以帮我弄清楚为什么循环语句无法解析$this-> footerList->项吗?
解决方法:
它应该是
foreach ($this->footerList["items"] as $item)
标签:arrays,php,object
来源: https://codeday.me/bug/20191201/2077687.html