Last active
November 30, 2018 06:36
-
-
Save MilesChou/b50ac37bad88d4ba1654e8a9b9ceeea4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$totalScore = 0; | |
foreach ($exam as $value) { | |
foreach ($value->mocks as $mock) { | |
foreach ($mock->items as $item) { | |
$totalScore += (int)$item->ext->score; | |
} | |
} | |
} | |
$totalScore = collect($exam)->flatMap->mocks->flatMap->items->reduce(function ($c, $v) { | |
$c += $v->ext->score; | |
return $c; | |
}, 0); | |
// --------------------------------- | |
$totalScore = 0; | |
foreach ($exam as $value) { | |
foreach ($value->mocks as $mock) { | |
foreach ($mock->items as $item) { | |
$totalScore += (int)$item->score; | |
} | |
} | |
} | |
$totalScore = collect($exam)->flatMap->mocks->flatMap->items->sum->score; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment