In this tutorial, you will learn Laravel Arr pluck() function Example
Example:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\FileController;
use Illuminate\Support\Arr;
class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$array1 = [
['developer' => ['id' => 1, 'name' => 'Mehul']],
['developer' => ['id' => 2, 'name' => 'Dharmik']],
];
$names1 = Arr::pluck($array, 'developer.name');
// ['Mehul', 'Dharmik']
$array2 = [
['product' => ['id' => 1, 'name' => 'Pen', 'price' => '100']],
['product' => ['id' => 2, 'name' => 'Book', 'price' => '200']],
];
$names2 = Arr::pluck($array, 'product.price');
// ['100', '200']
}
}
May this example help you.