Published in Laravel 5

Laravel 5: Determining if an Object is Array Accessible With accessible

By John Koster

The accessible helper method is used to determine whether the given $value is array accessible. A value $value is array accessible if the value is an array or an instance of ArrayAccess.

#Signature

The signature of the accessible method is:

1public static function accessible(
2 $value
3);

#Example Use

The following examples demonstrate the usage of the accessible helper method. The results of the method call appear above the call as a comment:

1
2// Create some test objects to work with.
3$array = [];
4$collection = collect([]);
5$model = factory('App\User')->make();
6$class = new stdClass;
7
8// true
9Arr::accessible($array);
10
11// true
12Arr::accessible($collection);
13
14// true
15Arr::accessible($model);
16
17// false
18Arr::accessible($class);
19
20// false
21Arr::accessible(null);