How to use Arr::pluck() helper function in laravel 10, In this comprehensive post I will tell you about the laravel 10 helper function Arr::pluck(), we do no more required to use the array_column() php function. as well as we can also use a multidimensional array with "DOT" notation.
You may also access a multidimensional array inside keys using "." Dot notation. Using the array pluck helper function you may get an array column value while you working with multiple arrays. This helper function also may use to find specific array key values.
In Laravel 10, you can use the pluck() method to pluck the values of a given key from an array of arrays. It returns the values from a single column of the array.
Usage of Arr::pluck() example, I have given different examples, by reading this post example you will be very clear about this helper function. I have given examples and how they output in this post given. This helper function also performs the array_column() php function role, as well as some additional tricks of use this function also details noted.
Exmaple 1: Use Simple Arr::pluck()
Simply you can easily use with an array, in this Arr::pluck() two-argument passed, in that first is an array and second is which array you want to retrieve that key.
In this example, I have to retrieve the name from the array using the array pluck laravel helper function.
use Illuminate\Support\Arr; $array = [ ['name' => 'Jone', 'age' => 23], ['name' => 'Mike', 'age' => 18], ['name' => 'Jordan', 'age' => 31], ['name' => 'Rickey', 'age' => 28], ['name' => 'Russle', 'age' => 21], ]; $names = Arr::pluck($array, 'name'); // OUTPUT array:5 [▼ 0 => "Jone" 1 => "Mike" 2 => "Jordan" 3 => "Rickey" 4 => "Russle" ]
Exmaple 2: Use Arr::pluck() With Dot Notation
In this example, I have passed a multi-dimensional array using "DOT" notation easy to find out the developer name from the multidimensional array. also, you can still live multidimensional array inside developer.
use Illuminate\Support\Arr; $array = [ ['developer' => ['name' => 'Jone', 'age' => 23]], ['developer' => ['name' => 'Mike', 'age' => 18]], ['developer' => ['name' => 'Jordan', 'age' => 31]], ['developer' => ['name' => 'Rickey', 'age' => 28]], ['developer' => ['name' => 'Russle', 'age' => 21]], ]; $names = Arr::pluck($array, 'developer.name'); // OUTPUT array:5 [▼ 0 => "Jone" 1 => "Mike" 2 => "Jordan" 3 => "Rickey" 4 => "Russle" ] $age = Arr::pluck($array, 'developer.age'); array:5 [▼ 0 => 23 1 => 18 2 => 31 3 => 28 4 => 21 ]
Example 3: User Arr::pluck() With List Key
In this last example you can see that I have passed the third argument in Arr::pluck() helper function, which will return list.name as key and age as value.
use Illuminate\Support\Arr; $array = [ ['developer' => ['name' => 'Jone', 'age' => 23]], ['developer' => ['name' => 'Mike', 'age' => 18]], ['developer' => ['name' => 'Jordan', 'age' => 31]], ['developer' => ['name' => 'Rickey', 'age' => 28]], ['developer' => ['name' => 'Russle', 'age' => 21]], ]; $age = Arr::pluck($array, 'developer.age','developer.name'); // OUTPUT array:5 [▼ "Jone" => 23 "Mike" => 18 "Jordan" => 31 "Rickey" => 28 "Russle" => 21 ]
We always thanks to you for reading our blogs.

Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- Different Solutions For Fix 419 Page Expired laravel
- Laravel 10 Firebase Web Push Notification Tutorial
- How to Send Email with Laravel 10
- Laravel One to One Eloquent Relationship Tutorial
- Laravel Custom Command Make Example
- How to Generate PDF in Laravel 6 Example
- Laravel 9 REST API with Passport Authentication Tutorial
- How To Generate Image From HTML Using Snappy In Laravel 9
- How to Create Zip File and Download in Laravel
- Laravel Upgrading To 10.0 From 9.x Version