protected function checkRegexRecursively($array, $pattern, $accessKey = null)
    {
        $found = [];

        if (!is_array($array) && !is_object($array)) {
            return [];
        }

        if ($array instanceof Collection || $array instanceof Model) {
            $array = $array->toArray();
        }

        foreach ($array as $index => $value) {
            $newAccessKey = ($accessKey ? $accessKey.'.' : '').$index;

            if (preg_match($pattern, $newAccessKey, $matches)) {
                $found[] = $matches;
            }

            $found = array_merge($found, $this->checkRegexRecursively($value, $pattern, $newAccessKey));
        }

        return $found;
    }
protected function checkRegexRecursively($array, $pattern, $accessKey = null)
    {
        $found = [];

        if (!is_array($array) && !is_object($array)) {
            return [];
        }

        if ($array instanceof Collection || $array instanceof Model) {
            $array = $array->toArray();
        }

        foreach ($array as $index => $value) {
            $newAccessKey = ($accessKey ? $accessKey.'.' : '').$index;

            if (preg_match($pattern, $newAccessKey, $matches)) {
                $found[] = $matches;
            }

            $found = array_merge($found, $this->checkRegexRecursively($value, $pattern, $newAccessKey));
        }

        return $found;
    }
protected function checkRegexRecursively ( $ array , $ pattern , $ accessKey = null ) { $ found = [ ] ; if ( ! is_array ( $ array ) && ! is_object ( $ array ) ) { return [ ] ; } if ( $ array instanceof Collection || $ array instanceof Model ) { $ array = $ array -> toArray ( ) ; } foreach ( $ array as $ index => $ value ) { $ newAccessKey = ( $ accessKey ? $ accessKey . '.' : '' ) . $ index ; if ( preg_match ( $ pattern , $ newAccessKey , $ matches ) ) { $ found [ ] = $ matches ; } $ found = array_merge ( $ found , $ this -> checkRegexRecursively ( $ value , $ pattern , $ newAccessKey ) ) ; } return $ found ; }
Loop through the given array|object and check the given regular expression on every single item.

@param array  $array
@param string $pattern
@param string $accessKey

@return array
Loop through the given array|object and check the given regular expression on every single item .