From 3c771bb955334942ad82917ac70c21e5a9d15013 Mon Sep 17 00:00:00 2001 From: Milwad <98118400+milwad-dev@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:17:51 +0330 Subject: [PATCH] Update collections.md --- collections.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/collections.md b/collections.md index be8b7f7259f..e728704a709 100644 --- a/collections.md +++ b/collections.md @@ -2251,6 +2251,23 @@ $plucked->all(); // ['Tesla' => 'black', 'Pagani' => 'orange'] ``` +The `pluck()` method also supports Closure for retrieving values: + +```php +$countryArray = [ + ['id' => 1, 'flag' => '🇺🇸', 'name' => 'United States'], + ['id' => 2, 'flag' => '🇫🇷', 'name' => 'France'], + ['id' => 3, 'flag' => '🇮🇷', 'name' => 'Iran'], +]; + +$countries = collect($countryArray)->pluck( + fn ($country) => "{$country['flag']} {$country['name']}", + 'id', +); + +// [1 => '🇺🇸 United States', 2 => '🇫🇷 France', 3 => '🇮🇷 Iran'] +``` + #### `pop()` {.collection-method}