src/Traits/Collections.php
public static function get($collection = [], $key = null, $default = null)
    {
        if (__::isNull($key)) {
            return $collection;
        }

        if (!__::isObject($collection) && isset($collection[$key])) {
            return $collection[$key];
        }

        foreach (explode('.', $key) as $segment) {
            if (__::isObject($collection)) {
                if (!isset($collection->{$segment})) {
                    return $default instanceof Closure ? $default() : $default;
                } else {
                    $collection = $collection->{$segment};
                }
            } else {
                if (!isset($collection[$segment])) {
                    return $default instanceof Closure ? $default() : $default;
                } else {
                    $collection = $collection[$segment];
                }
            }
        }

        return $collection;
    }
public static function get($collection = [], $key = null, $default = null)
    {
        if (__::isNull($key)) {
            return $collection;
        }

        if (!__::isObject($collection) && isset($collection[$key])) {
            return $collection[$key];
        }

        foreach (explode('.', $key) as $segment) {
            if (__::isObject($collection)) {
                if (!isset($collection->{$segment})) {
                    return $default instanceof Closure ? $default() : $default;
                } else {
                    $collection = $collection->{$segment};
                }
            } else {
                if (!isset($collection[$segment])) {
                    return $default instanceof Closure ? $default() : $default;
                } else {
                    $collection = $collection[$segment];
                }
            }
        }

        return $collection;
    }
public static function get ( $ collection = [ ] , $ key = null , $ default = null ) { if ( __ :: isNull ( $ key ) ) { return $ collection ; } if ( ! __ :: isObject ( $ collection ) && isset ( $ collection [ $ key ] ) ) { return $ collection [ $ key ] ; } foreach ( explode ( '.' , $ key ) as $ segment ) { if ( __ :: isObject ( $ collection ) ) { if ( ! isset ( $ collection -> { $ segment } ) ) { return $ default instanceof Closure ? $ default ( ) : $ default ; } else { $ collection = $ collection -> { $ segment } ; } } else { if ( ! isset ( $ collection [ $ segment ] ) ) { return $ default instanceof Closure ? $ default ( ) : $ default ; } else { $ collection = $ collection [ $ segment ] ; } } } return $ collection ; }
Get item of an array by index, accepting nested index

@usage __::get(['foo' => ['bar' => 'ter']], 'foo.bar');
>> 'ter'

@param array|object $collection array of values
@param null|string  $key        key or index
@param mixed        $default    default value to return if index not exist

@return mixed
Get item of an array by index accepting nested index