for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Rogierw\RwAcme\Support;
use ArrayAccess;
class Arr
{
public static function accessible($value)
return is_array($value) || $value instanceof ArrayAccess;
}
public static function exists($array, $key)
if ($array instanceof ArrayAccess) {
return $array->offsetExists($key);
return array_key_exists($key, $array);
public static function get($array, $key, $default = null)
if (!static::accessible($array)) {
return value($default);
if (is_null($key)) {
return $array;
if (static::exists($array, $key)) {
return $array[$key];
if (strpos($key, '.') === false) {
return $array[$key] ?? value($default);
foreach (explode('.', $key) as $segment) {
if (static::accessible($array) && static::exists($array, $segment)) {
$array = $array[$segment];
} else {
public static function first($array, callable $callback = null, $default = null)
if (is_null($callback)) {
if (empty($array)) {
foreach ($array as $item) {
return $item;
foreach ($array as $key => $value) {
if ($callback($value, $key)) {
return $value;