Less than 1 minute
Array Utilities (Hazaar\Util\Arr)
Hazaar\Util\Arr::get() - Array Key Exists
The ake() function is now replaced by Hazaar\Util\Arr::get(). This method allows you to retrieve a value from an array (or object) using advanced search capabilities, including dot-notation and search parameters.
Example
use Hazaar\Util\Arr;
$array = ['key' => 'value'];
echo Arr::get($array, 'key'); // Outputs: valueYou can also use dot-notation for nested arrays:
$array = ['user' => ['name' => 'Jamie']];
echo Arr::get($array, 'user.name'); // Outputs: JamieFor more advanced usage and options, see the Arr class API documentation.
Hazaar\Util\Arr::flatten() and Arr::unflatten()
Flatten a multidimensional array into a string, and convert it back:
$array = ['foo' => 'bar', 'baz' => 'qux'];
$flat = Arr::flatten($array); // foo=bar;baz=qux
$unflat = Arr::unflatten($flat); // ['foo' => 'bar', 'baz' => 'qux']Hazaar\Util\Arr::collate()
Collate a multidimensional array into an associative array by a key:
$users = [
['id' => 1, 'name' => 'Alice'],
['id' => 2, 'name' => 'Bob'],
];
$collated = Arr::collate($users, 'id', 'name'); // [1 => 'Alice', 2 => 'Bob']Hazaar\Util\Arr::enhance()
Merge two arrays, only adding elements that don't already exist in the target array:
$a = ['foo' => 1];
$b = ['foo' => 2, 'bar' => 3];
$enhanced = Arr::enhance($a, $b); // ['foo' => 1, 'bar' => 3]Hazaar\Util\Arr::grammaticalImplode()
Implode an array in a grammatically correct way:
$items = ['One', 'Two', 'Three'];
echo Arr::grammaticalImplode($items); // One, Two and Three