protected function pregGrepRecursive($pattern, $haystack)
    {
        $matches = [];
        
        foreach ($haystack as $key => $item) {
            if (is_array($item)) {
                $sub_matches = $this->pregGrepRecursive($pattern, $item);
                
                if ($sub_matches) {
                    $matches[$key] = $sub_matches;
                }
            } elseif (preg_match($pattern, $item)) {
                $matches[$key] = $item;
            }
        }
        
        return $matches;
    }