In this tutorial you will learn about the Laravel Arr dot() function Example and its application with practical example.
Laravel Arr dot() function Example
In this article, I’ll show you how to use laravel Arr dot() function with example. We will show example of Arr dot() function in laravel. In this tutorial, we will use Arr dot() function to flatten a multi-dimensional array into a single level array using “dot” notation.
Laravel Arr::dot method
The Arr::dot method flattens a multi-dimensional array into a single level array using “dot” notation to indicate depth.
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 30 31 32 33 |
<?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 = ['products' => ['toys' => ['price' => 100]]]; $doted1 = Arr::dot($array1); print_r($doted1); //['products.toys.price' => 100] echo "<br>"; $array2 = ['technologies' => ['laptop' => 'Dell']]; $doted2 = Arr::dot($array2); print_r($doted2); //['technologies.laptop' => 'dell'] } } |
Output:-
1 2 |
Array ( [products.toys.price] => 100 ) Array ( [technologies.laptop] => Dell ) |