10-Apr-2023
.
Admin
Hi Guys,
In this blog, I will explain to you how to work laravel array dot() function. We will show example of array dot function to get array dot element value in laravel. The Arr::dot method flattens a multi-dimensional array into a single level array that uses "dot" notation to indicate depth.
Here, I will give you full example for simply Arr dot() method in laravel as below.
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 = ['products' => ['toys' => ['price' => 100]]];
$doted1 = Arr::dot($array1);
print_r($doted1);
//['products.toys.price' => 100]
$array2 = ['technologies' => ['laptop' => 'Dell']];
$doted2 = Arr::dot($array2);
print_r($doted2);
//['technologies.laptop' => 'dell']
}
}
Output
['products.toys.price' => 100]
['technologies.laptop' => 'dell']
It Will help you...
#Laravel 8
#Laravel 7
#Laravel
#Laravel 6