In this tutorial, We will learn how to use the laravel array hasAny() function example. We will show an example of an array hasAny() function in laravel.


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


Thanks, May this example will help you.