{#186 ▼
+"results": Collection {#203 ▼
#items: array:15 [▼
0 => {#218 ▼
+"wrapperType": "track"
+"kind": "song"
+"artistId": 32940
+"collectionId": 159292399
+"trackId": 159293848
+"artistName": "Michael Jackson"
+"collectionName": "The Essential Michael Jackson"
+"trackName": "Billie Jean"
+"collectionCensoredName": "The Essential Michael Jackson"
+"trackCensoredName": "Billie Jean (Single Version)"
+"artistViewUrl": "https://itunes.apple.com/us/artist/michael-jackson/id32940?uo=4"
+"collectionViewUrl": "https://itunes.apple.com/us/album/billie-jean-single-version/id159292399?i=159293848&uo=4"
+"trackViewUrl": "https://itunes.apple.com/us/album/billie-jean-single-version/id159292399?i=159293848&uo=4"
+"previewUrl": "https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/AudioPreview122/v4/c6/50/11/c6501132-e865-3711-175a-ddb79114e42f/mzaf_3806132797788612279.plus.aac ▶"
+"artworkUrl30": "http://is2.mzstatic.com/image/thumb/Music127/v4/8a/65/be/8a65bef2-f23d-e43d-9124-f5e4293513f7/source/30x30bb.jpg"
+"artworkUrl60": "http://is2.mzstatic.com/image/thumb/Music127/v4/8a/65/be/8a65bef2-f23d-e43d-9124-f5e4293513f7/source/60x60bb.jpg"
+"artworkUrl100": "http://is2.mzstatic.com/image/thumb/Music127/v4/8a/65/be/8a65bef2-f23d-e43d-9124-f5e4293513f7/source/100x100bb.jpg"
+"collectionPrice": 16.99
+"trackPrice": 1.29
+"trackNumber": 16
+"trackTimeMillis": 294601
+"country": "USA"
+"currency": "USD"
+"primaryGenreName": "Pop"
+"isStreamable": true
}
1 => {#217 ▶}
2 => {#216 ▶}
3 => {#215 ▶}
答案 0 :(得分:2)
这是一个简单的可迭代对象,没有什么特别的或与Laravel相关的。
你可以这样做:
$sum = 0;
foreach ($response['results']->items as $item) {
$sum += $item->trackTimeMillis;
}
var_dump($sum);
答案 1 :(得分:1)
你应该可以用一行代码来做到这一点:
$total = $response->results->sum('trackTimeMillis');