gpt4 book ai didi

php - 如何在 php 中访问 stdclass 对象?

转载 作者:行者123 更新时间:2023-12-04 18:48:10 27 4
gpt4 key购买 nike

这是我的对象:

$reportdata = stdClass Object
(
[1] => stdClass Object
(
[reportname] => reportname1
[reportviews] => 20
[reportpath] => reports/reportname1
[thumbnailurl] => reports/thumbnailurl/thumbnailurl1.jpg
[description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
)

[2] => stdClass Object
(
[reportname] => reportname2
[reportviews] => 20
[reportpath] => reports/reportname2
[thumbnailurl] => reports/thumbnailurl/thumbnailurl2.jpg
[description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
)


)

我正在尝试使用 $reportdata[1]['reportviews'] 访问各个值,但出现错误

"Cannot use object of type stdClass as array".

如何访问 reportnamereportviews

最佳答案

像这样:$reportdata->{1}->reportviews

关于php - 如何在 php 中访问 stdclass 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45103712/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com