In this tutorial you will learn about the Laravel Arr get() function Example and its application with practical example.
Laravel Arr get() function Example
In this article, I’ll show you how to use laravel Arr get() function with example. We will show example of Arr get() function in laravel. In this tutorial, we will use Arr get() function to get a value from a deeply nested array using “dot” notation.
Laravel Arr::get method
The Arr::get method retrieves a value from a deeply nested array using “dot” notation.
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?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() { $array = ['products' => ['desk' => ['price' => 500]]]; $price = Arr::get($array, 'products.desk.price'); print_r($price); echo "<br>"; $array1 = ['car' => ['bmw' => ['no' =>'QX-100',],'honda' => ['no' =>'CA-888',]]]; $price1 = Arr::get($array1, 'car.bmw.no'); print_r($price1); } } |
Output:-
1 2 |
500 QX-100 |