Laravel Arr has() function Example

10-Apr-2023

.

Admin

Laravel Arr has() function Example

Hi Guys,

In this blog, I will explain to you how to work laravel array has() function. We will show example of array has function to get array has element value in laravel. The Arr::has method checks whether a given item or items exists in an array using "dot" notation.

Here, I will give you a full example for simply Arr has() method in laravel as bellow.

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()

{

$array = ['car' => ['name' => 'Desk', 'price' => 100]];

$contains = Arr::has($array, 'car.name');

// true

$contains = Arr::has($array, ['car.price', 'car.discount']);

// false

}

}

Output

true

false

It Will help you...

#Laravel 8

#Laravel 7

#Laravel

#Laravel 6