$users = [ ['name' => 'John', 'age' => 30], ['name' => 'Jane', 'age' => 25], ['name' => 'Bob', 'age' => 35] ]; // extract all the names from the array $names = Arr::pluck($users, 'name'); // $names will contain ['John', 'Jane', 'Bob']
$products = collect([ ['name' => 'Apple', 'price' => 2.5], ['name' => 'Banana', 'price' => 1.5], ['name' => 'Orange', 'price' => 3.0] ]); // extract all the prices from the collection $prices = $products->pluck('price'); // $prices will contain [2.5, 1.5, 3.0]This function is part of the Laravel Collection package library, which provides a wide range of useful methods for working with arrays and collections.