Scrap Arr::dot and put dot notation support in Arr::get.
This commit is contained in:
parent
db5c61d50c
commit
28c6ac93ef
|
@ -5,7 +5,8 @@ class Arr {
|
||||||
/**
|
/**
|
||||||
* Get an item from an array.
|
* 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 array $array
|
||||||
* @param string $key
|
* @param string $key
|
||||||
|
@ -19,29 +20,6 @@ public static function get($array, $key, $default = null)
|
||||||
return $array;
|
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)
|
foreach (explode('.', $key) as $segment)
|
||||||
{
|
{
|
||||||
if ( ! isset($array[$segment]))
|
if ( ! isset($array[$segment]))
|
||||||
|
|
Loading…
Reference in New Issue