我希望你能帮助我解决这个将对象数组转换为单个对象的简单问题。所以我可以直接调用它们的属性。
我的意思是,我在下面列出了这些数据:
array(3) {
[0]=>
object(stdClass)#259 (8) {
["id"]=>
int(2)
["author_id"]=>
int(2)
["title"]=>
string(17) "The Emperorasdasd"
["publisher"]=>
string(15) "De publishing"
["created_at"]=>
string(19) "2013-10-11 12:49:00"
["updated_at"]=>
string(19) "2013-10-12 09:44:58"
["date_published"]=>
string(10) "02-12-2013"
["name"]=>
string(8) "John Doe"
}
[1]=>
object(stdClass)#260 (8) {
["id"]=>
int(1)
["author_id"]=>
int(1)
["title"]=>
string(4) "Demo"
["publisher"]=>
string(10) "ooqwwoeqoe"
["created_at"]=>
string(19) "2013-10-12 09:45:31"
["updated_at"]=>
string(19) "2013-10-12 09:45:36"
["date_published"]=>
string(10) "26-12-1993"
["name"]=>
string(11) "Demo"
}
[2]=>
object(stdClass)#261 (8) {
["id"]=>
int(1)
["author_id"]=>
int(1)
["title"]=>
string(12) "Read My Mind"
["publisher"]=>
string(13) "TF Publishing"
["created_at"]=>
string(19) "2013-10-12 09:46:53"
["updated_at"]=>
string(19) "2013-10-12 09:46:53"
["date_published"]=>
string(10) "30-11-2009"
["name"]=>
string(11) "James Mones"
}
}
如何将 3 项数组转换为 3 个单独的对象?所以我可以像这样直接称呼他们:$books->id
,不是$books[0]->id
?