public static function fetch($array, $path, $default = null)
    {
        // $array must be an array
        if (!is_array($array)) {
            return $default;
        }

        if ($path === '') {
            return $array;
        }

        $path = is_array($path) ? $path : explode('.', $path);
        $levels = count($path);

        // No path means the received array
        if ($levels === 0) {
            return $array;
        }

        $ret = $default;
        $key = array_shift($path);
        $levels -= 1;

        if (array_key_exists($key, $array)) {
            if (is_array($array[$key]) && $levels > 0) {
                $ret = self::fetch($array[$key], $path, $default);
            } else {
                $ret = $array[$key];
            }
        }

        return $ret;
    }
public static function fetch($array, $path, $default = null)
    {
        // $array must be an array
        if (!is_array($array)) {
            return $default;
        }

        if ($path === '') {
            return $array;
        }

        $path = is_array($path) ? $path : explode('.', $path);
        $levels = count($path);

        // No path means the received array
        if ($levels === 0) {
            return $array;
        }

        $ret = $default;
        $key = array_shift($path);
        $levels -= 1;

        if (array_key_exists($key, $array)) {
            if (is_array($array[$key]) && $levels > 0) {
                $ret = self::fetch($array[$key], $path, $default);
            } else {
                $ret = $array[$key];
            }
        }

        return $ret;
    }
public static function fetch ( $ array , $ path , $ default = null ) { // $array must be an array if ( ! is_array ( $ array ) ) { return $ default ; } if ( $ path === '' ) { return $ array ; } $ path = is_array ( $ path ) ? $ path : explode ( '.' , $ path ) ; $ levels = count ( $ path ) ; // No path means the received array if ( $ levels === 0 ) { return $ array ; } $ ret = $ default ; $ key = array_shift ( $ path ) ; $ levels -= 1 ; if ( array_key_exists ( $ key , $ array ) ) { if ( is_array ( $ array [ $ key ] ) && $ levels > 0 ) { $ ret = self :: fetch ( $ array [ $ key ] , $ path , $ default ) ; } else { $ ret = $ array [ $ key ] ; } } return $ ret ; }
Fetch nested array value by dot notation path.

Arr::fetch('key1.key2', $arr);

@param array        $array   The array to get value from.
@param string|array $path    The key in dot notation. You can also pass array with keys.
@param mixed        $default The default value if key does not exist.

@return mixed
Fetch nested array value by dot notation path .