10-Apr-2023
.
Admin
Hi Guys,
In this blog,I will you how to use laravel array hasAny() function example. We will show example of array hasAny function in laravel.The Arr::hasAny method checks whether any item in a given set exists in an array using "dot" notation.
Here, I will give you full example for simply Arr hasAny() 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 = ['bike' => ['name' => 'Desk', 'price' => 100]];
$contains1 = Arr::hasAny($array, 'bike.name');
print_r($contains1);
// true
$contains2 = Arr::hasAny($array, ['bike.name', 'product.discount']);
print_r($contains2);
// true
$contains3 = Arr::hasAny($array, ['category', 'bike.discount']);
print_r($contains3);
// false
}
}
Output
true
true
false
It Will help you...
#Laravel 8
#Laravel 7
#Laravel
#Laravel 6