我希望在將對象數組轉換爲單個對象時,可以幫助我解決這個簡單問題。所以我可以直接調用它們的屬性。Laravel 4 - 將對象數組轉換爲單個對象
我的意思是,我有這個數據如下:
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
?