Arr.php
public static function get(array $array, $key = null, $default = null, string $delimiter = null)
    {
        // Make loops easier for the end-user - return the initial array if the key is null instead of forcing
        // a valid value.
        if (!isset($key)) {
            return $array;
        }

        // Which string delimiter should we use?
        if (!isset($delimiter)) {
            $delimiter = static::$delimiter;
        }

        // If the key is string delimited, we need to explode it into an array of segments.
        $segments = is_array($key) ? $key : explode($delimiter, $key);

        // One dimension at a time.
        while ($segment = array_shift($segments)) {

            // If the current segment is a wildcard, make sure the it points to an array
            // and pluck the remaining segments from it.
            if ($segment === '*') {
                return is_array($array) ? static::pluck($array, $segments, $delimiter) : $default;
            }

            // Note: isset() is the cheapest condition to check for while being rather probable at the same time,
            // thus the seemingly unintuitive condition ordering.
            if (isset($array->{$segment})) {
                $array = $array->{$segment};
            } elseif (is_array($array) && array_key_exists($segment, $array)) {
                $array = $array[$segment];
            } else {
                return $default;
            }
        }

        return $array;
    }
public static function get(array $array, $key = null, $default = null, string $delimiter = null)
    {
        // Make loops easier for the end-user - return the initial array if the key is null instead of forcing
        // a valid value.
        if (!isset($key)) {
            return $array;
        }

        // Which string delimiter should we use?
        if (!isset($delimiter)) {
            $delimiter = static::$delimiter;
        }

        // If the key is string delimited, we need to explode it into an array of segments.
        $segments = is_array($key) ? $key : explode($delimiter, $key);

        // One dimension at a time.
        while ($segment = array_shift($segments)) {

            // If the current segment is a wildcard, make sure the it points to an array
            // and pluck the remaining segments from it.
            if ($segment === '*') {
                return is_array($array) ? static::pluck($array, $segments, $delimiter) : $default;
            }

            // Note: isset() is the cheapest condition to check for while being rather probable at the same time,
            // thus the seemingly unintuitive condition ordering.
            if (isset($array->{$segment})) {
                $array = $array->{$segment};
            } elseif (is_array($array) && array_key_exists($segment, $array)) {
                $array = $array[$segment];
            } else {
                return $default;
            }
        }

        return $array;
    }
public static function get ( array $ array , $ key = null , $ default = null , string $ delimiter = null ) { // Make loops easier for the end-user - return the initial array if the key is null instead of forcing // a valid value. if ( ! isset ( $ key ) ) { return $ array ; } // Which string delimiter should we use? if ( ! isset ( $ delimiter ) ) { $ delimiter = static :: $ delimiter ; } // If the key is string delimited, we need to explode it into an array of segments. $ segments = is_array ( $ key ) ? $ key : explode ( $ delimiter , $ key ) ; // One dimension at a time. while ( $ segment = array_shift ( $ segments ) ) { // If the current segment is a wildcard, make sure the it points to an array // and pluck the remaining segments from it. if ( $ segment === '*' ) { return is_array ( $ array ) ? static :: pluck ( $ array , $ segments , $ delimiter ) : $ default ; } // Note: isset() is the cheapest condition to check for while being rather probable at the same time, // thus the seemingly unintuitive condition ordering. if ( isset ( $ array -> { $ segment } ) ) { $ array = $ array -> { $ segment } ; } elseif ( is_array ( $ array ) && array_key_exists ( $ segment , $ array ) ) { $ array = $ array [ $ segment ] ; } else { return $ default ; } } return $ array ; }
Returns a string delimited key from an array, with a default value if the given key does not exist. If null
is given instead of a key, the whole initial array will be returned.

Note: Nested objects will be accessed as if they were arrays, eg. if "some.nested.object" is an object,
then looking for "some.nested.object.property" will be handled just as a normal array would.

@param   array           $array      The array to search in.
@param   string|array    $key        The string delimited key or a chain (array) of nested keys pointing
to the desired key.
@param   mixed           $default    The default value.
@param   string          $delimiter  The delimiter to use when exploding the key into parts.
@return  mixed
Returns a string delimited key from an array with a default value if the given key does not exist . If null is given instead of a key the whole initial array will be returned .