In this tutorial you will learn about the Laravel Arr exists() function Example and its application with practical example.
Laravel array exists() function Example
In this article, I’ll show you how to use laravel array exists() function with example. We will show example of array exists() function in laravel. In this tutorial, we will use array exists() function to checks that the given key exists in the provided array.
Laravel Arr::exists method
The Arr::exists method checks that the given key exists in the provided array.
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 |
<?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 = ['name' => 'steve', 'age' => 21]; $exists1 = Arr::exists($array1, 'name'); var_dump($exists1); echo "<br>"; $array2 = ['language' => 'php', 'server' => 'apache']; $exists2 = Arr::exists($array2, 'name'); var_dump($exists2); } } |
Output:-
1 2 |
bool(true) bool(false) |