Commit dfbd8e79 authored by Taylor Otwell's avatar Taylor Otwell

Added Arr::dot method.

parent 6c149b28
......@@ -27,4 +27,27 @@ class Arr {
return is_callable($default) ? call_user_func($default) : $default;
}
/**
* Get an item from an array using JavaScript style "dot" notation.
*
* @param array $array
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function dot($array, $key, $default = null)
{
foreach (explode('.', $key) as $segment)
{
if ( ! isset($array[$segment]))
{
return is_callable($default) ? call_user_func($default) : $default;
}
$array = $array[$segment];
}
return $array;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment