Laravel Arr dot() function Example

In this example, I will explain to you how to work laravel array dot() function. Array dot function to get array dot element value in laravel application. The Arr::dot function flattens a multi-dimensional array into a single level array that uses “dot” notation to indicate depth.

Laravel Arr dot method is most important when you get multidimensional array single value using dot.

Read Also :  Laravel Eloquent whereBetween Example

Laravel array dot function 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']
    }
}

I hope you understand of laravel arr dot() function and it can help you…