Array helpers
Arrays are the bread and butter of any web application that deals with data. PHP already offers nearly 80 functions to perform various operations on arrays, and Laravel complements them with a handful of practical functions that are inspired by certain functions found in Python and Ruby.
Note
Several of Laravel's classes, including Eloquent collections, implement the PHP ArrayAccess
interface. This means that you can use them like a normal array in your code and, for instance, iterate over the items in a foreach
loop or use them with the array functions described here.
Most of the functions support a dot notation to refer to nested values, which is similar to JavaScript objects. For example, rather than writing $arr['foo']['bar']['baz']
, you can use the array_get
helper and write array_get($arr, 'foo.bar.baz');
.
In the following usage examples, we will use three dummy arrays and assume that they are reset for each example:
$associative...