PHP - 无法访问 stdclass 对象中的数组

PHP - Cannot access array in stdclass object

目前我有一个标准类对象。如何访问对象的属性,例如作者姓名?我试图回显 $authors = $book->authors_summary[0]->name; 但它 returns 'Trying to get property of non-object in ...' 错误。

[authors_summary] => Array
        (
            [0] => Array
                (
                    [id] => 123456789
                    [name] => Ben Smith
                )

            [1] => Array
                (
                    [nconst] => 987654321
                    [name] => Tommy Lee
                )

        )

你的authors_summary[0]是一个数组,所以你不能使用->对象指针,你必须将它作为数组调用:

$authors = $book->authors_summary[0]['name'];

'name' 是数组的键,因此您可以像这样访问名称值

$authors = $book->authors_summary[0]['name'];
echo $authors;

数组 ( [数据] => 数组 ( [0] => 标准类对象 ( [编号] => 5 [名称] => 尼禄 [电子邮件] => nilu@gmail.com [密码] => nilu [图片] => LOVE_A_O_D.jpg )

    )

)

如何从这里获取密码..... 在控制器---- $datas['data']= $this->Login_model->loginchk($value);

模型中----- $results=$this->db->get(); return $results->result();