public static function getBySelector($array, $selector)
    {
        if (strpos($selector, '[*]') === false) {
            return array(
                $selector => self::getByPath($array, $selector)
            );
        }
        $result = array();
        list($preffix, $suffix) = explode('[*]', $selector, 2);

        $base = self::getByPath($array, $preffix);
        if (! is_array($base)) {
            $base = array();
        }
        // we don't have a suffix, the selector was something like path[subpath][*]
        if (! $suffix) {
            foreach ($base as $k => $v) {
                $result["{$preffix}[{$k}]"] = $v;
            }
            // we have a suffix, the selector was something like path[*][item]
        } else {
            foreach ($base as $itemKey => $itemValue) {
                if (is_array($itemValue)) {
                    $result["{$preffix}[{$itemKey}]{$suffix}"] = self::getByPath($itemValue, $suffix);
                }
            }
        }

        return $result;
    }
public static function getBySelector($array, $selector)
    {
        if (strpos($selector, '[*]') === false) {
            return array(
                $selector => self::getByPath($array, $selector)
            );
        }
        $result = array();
        list($preffix, $suffix) = explode('[*]', $selector, 2);

        $base = self::getByPath($array, $preffix);
        if (! is_array($base)) {
            $base = array();
        }
        // we don't have a suffix, the selector was something like path[subpath][*]
        if (! $suffix) {
            foreach ($base as $k => $v) {
                $result["{$preffix}[{$k}]"] = $v;
            }
            // we have a suffix, the selector was something like path[*][item]
        } else {
            foreach ($base as $itemKey => $itemValue) {
                if (is_array($itemValue)) {
                    $result["{$preffix}[{$itemKey}]{$suffix}"] = self::getByPath($itemValue, $suffix);
                }
            }
        }

        return $result;
    }
public static function getBySelector ( $ array , $ selector ) { if ( strpos ( $ selector , '[*]' ) === false ) { return array ( $ selector => self :: getByPath ( $ array , $ selector ) ) ; } $ result = array ( ) ; list ( $ preffix , $ suffix ) = explode ( '[*]' , $ selector , 2 ) ; $ base = self :: getByPath ( $ array , $ preffix ) ; if ( ! is_array ( $ base ) ) { $ base = array ( ) ; } // we don't have a suffix, the selector was something like path[subpath][*] if ( ! $ suffix ) { foreach ( $ base as $ k => $ v ) { $ result [ "{$preffix}[{$k}]" ] = $ v ; } // we have a suffix, the selector was something like path[*][item] } else { foreach ( $ base as $ itemKey => $ itemValue ) { if ( is_array ( $ itemValue ) ) { $ result [ "{$preffix}[{$itemKey}]{$suffix}" ] = self :: getByPath ( $ itemValue , $ suffix ) ; } } } return $ result ; }
Get values in the array by selector

@example
Arr::getBySelector($data, 'email');
Arr::getBySelector($data, 'addresses[0][line]');
Arr::getBySelector($data, 'addresses[*][line]');

@param $array
@param $selector

@return array
Get values in the array by selector