pilat wrote a comment+100 XP
3mos ago
pilat wrote a comment+100 XP
4mos ago
pilat wrote a reply+100 XP
4mos ago
with unique(), the first item it stumbled upon will remain. BUT, this is not common for all the methods. In keyBy(), for example, the last item will replace anything before
$coll = [
['tag' => 1, 'value' => 11],
['tag' => 1, 'value' => 12],
['tag' => 2, 'value' => 21],
['tag' => 2, 'value' => 22],
];
[
'unique' => collect($coll)->unique('tag')->pluck('value')->all(),
// BUT!
'keyBy' => collect($coll)->keyBy('tag')->pluck('value')->all(),
];
// output:
[
"unique" => [11, 21],
"keyBy" => [12, 22],
]
pilat wrote a reply+100 XP
5mos ago