Scrap Arr::dot and put dot notation support in Arr::get.

This commit is contained in:
Taylor Otwell 2011-08-02 13:41:57 -05:00
parent db5c61d50c
commit 28c6ac93ef
1 changed files with 2 additions and 24 deletions

View File

@ -5,7 +5,8 @@ class Arr {
/**
* Get an item from an array.
*
* If the specified key is null, the entire array will be returned.
* If the specified key is null, the entire array will be returned. The array may
* also be accessed using JavaScript "dot" style notation.
*
* @param array $array
* @param string $key
@ -19,29 +20,6 @@ public static function get($array, $key, $default = null)
return $array;
}
if (array_key_exists($key, $array))
{
return $array[$key];
}
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)
{
if (is_null($key))
{
return $array;
}
foreach (explode('.', $key) as $segment)
{
if ( ! isset($array[$segment]))