Skip to content

Instantly share code, notes, and snippets.

@luscas
Last active February 9, 2020 20:30
Show Gist options
  • Save luscas/29d1aa166e9acd90fd7bcef8c9bc54f6 to your computer and use it in GitHub Desktop.
Save luscas/29d1aa166e9acd90fd7bcef8c9bc54f6 to your computer and use it in GitHub Desktop.
Collection
<?php
function peoples(): Collection {
$peoples = collect([
[
'sex' => 'masc',
'age' => 19
], [
'sex' => 'fem',
'age' => 4
], [
'sex' => 'masc',
'age' => 5
], [
'sex' => 'fem',
'age' => 13
], [
'sex' => 'fem',
'age' => 7
],
]);
return $peoples->groupBy([
'sex',
function (array $people) {
return (string) $people['age'];
}
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment