This version is outdated. You should upgrade your project to Mako 12.1!
Learn more

Array helper



The array helper contains methods that can be useful when working with arrays.


Usage

The phpget method returns a value from an array using "dot notation".

$array = ['foo' => ['bar' => 'baz']];

$bar = Arr::get($array, 'foo.bar');

// You can also specify a default value if the key doesn't exist

$baz = Arr::get($array, 'foo.baz', 'nope');

The phpset method sets an array value using "dot notation".

Arr::set($array, 'foo.baz', 'hello world');

The phpdelete method deletes an array value using "dot notation".

Arr::delete($array, 'foo.bar');

The phprandom method returns a random array value.

Arr::random(['green', 'blue', 'red', 'orange']);

The phpisAssoc method returns TRUE if the array is associative and FALSE if not.

// $assoc will be set to FALSE

$assoc = Arr::isAssoc([1, 2, 3]);

// $assoc will be set to TRUE

$assoc = Arr::isAssoc(['one' => 1, 'two' => 2, 'three' => 3]);

The phppluck method returns the values from a single column of the input array, identified by the key.

$fruits =
[
	['name' => 'apple', 'color' => 'green'],
	['name' => 'banana', 'color' => 'yellow'];
];

$colors = Arr::pluck($fruits, 'color');