@param array $array
@param string $pattern

@return mixed|null First matching value or null
968133
public static function getValue(&$array, $pattern)
    {
        $imploded = ArrDots::implode($array);
        $pattern  = sprintf('/^%s$/', str_replace(static::WILD, '[0-9]+', $pattern));

        foreach ($imploded as $attribute => $value) {
            if (preg_match($pattern, $attribute) == 0) {
                continue;
            }

            return $value;
        }

        return null;
    }
849245
private function regex_search_array($array, $regex) {
		$return = array();
		foreach ($array as $key => $item) {
	 		if(is_array($item)) {
	 			$tmp = $this->regex_search_array($item, $regex);
	 			if($tmp)
	 				$return[$key] = $tmp;
	 		} elseif(!is_object($item)) {
	 			//if (preg_match("/^.*".$regex.".*$/", $this->stripAccents($item))) {
	 			if (preg_match("/".$regex."/i", $this->stripAccents($item))) {
	                $return[$key] = $item;
	           	}
	 		}
		}
	 	
	    return $return;
	}
51810
public static function first( $array, $callback, $default = NULL )
    {
        foreach ( $array as $key => $value )
        {
            if ( call_user_func( $callback, $key, $value ) ) return $value;
        }

        return Util::value( $default );
    }
339877
public function getCount( $pattern = NULL )
	{
		$count	= 0;
		$list	= $this->getList( $pattern );
		foreach( $list as $entry )
			$count++;
		return $count;
	}
555270
public static function traceLeoCall(array $trace)
    {
        for ($i = count($trace) - 1; $i >= 0; --$i) {
            if (self::isLeoTraceEntry($trace[$i])) {
                return $trace[$i];
            }
        }

        return null;
    }
1159647
public function getMatchAll(string $pattern, int $flags = PREG_PATTERN_ORDER, int $offset = 0)
	{
		return preg_match_all($pattern, $this->str, $matches, $flags, $offset) === false ? null : $matches;
	}
755549
public function whenRegex($pattern, $name, $methods = null)
	{
		if ( ! is_null($methods)) $methods = array_map('strtoupper', (array) $methods);

		$this->regexFilters[$pattern][] = compact('name', 'methods');
	}
305544
public function list_tags($pattern = null) {
		$tagArray = explode("\n", $this->run("tag -l $pattern"));
		foreach ($tagArray as $i => &$tag) {
			$tag = trim($tag);
			if ($tag == '') {
				unset($tagArray[$i]);
			}
		}

		return $tagArray;
	}
665527
public function grep($values, $pattern, $flags = '')
    {
        if (!isset($values)) {
            return null;
        }
        
        if (is_string($flags)) {
            $flags = $flags === 'invert' ? PREG_GREP_INVERT : 0;
        }
        
        return preg_grep($pattern, $values, $flags);
    }
455920
private function find($pattern, $offset = null, $normal = false)
    {
        $source = $this->source;
        $offset = ($offset === null) ? $source->cursor : $offset;
        if ($offset >= $source->bound) {
            $this->addError('The scope of the parsing template is beyond the length of the template content');
            return null;
        }
        $content = $source->substring($offset, $source->bound);
        if (!preg_match($pattern, $content, $match, PREG_OFFSET_CAPTURE)) {
            return null;
        }
        $ret = $match[0];
        $length = strlen($ret[0]);
        if ($length == 0) {
            return null;
        }
        $start = $offset + $ret[1];
        $end = $start + $length;
        if ($normal) {
            return ['val' => $ret[0], 'idx' => 0, 'start' => $start, 'end' => $end, 'len' => $length];
        }
        $match = array_filter($match, function ($item) {
            return $item[1] != -1;
        });
        foreach ($match as $k => &$v) {
            $v[2] = $k - 1;
        }
        $ret = end($match);
        return ['val' => $ret[0], 'idx' => $ret[2], 'start' => $start, 'end' => $end, 'len' => $length];
    }
371390
public function matchesPattern($event, $pattern)
    {
        if ($pattern === '*') {
            return true;
        }

        if ($event == $pattern) {
            return true;
        }

        return fnmatch($pattern, $event);
    }
627679
public static function ksortRecursive(array &$array, $sortFlags = SORT_REGULAR)
    {
        /*
         * No elements?
         * Nothing to do
         */
        if (empty($array)) {
            return null;
        }

        $effect = &$array;
        ksort($effect, $sortFlags);

        foreach ($effect as &$value) {
            if (is_array($value)) {
                ksort($value, $sortFlags);
            }
        }

        return $effect;
    }
1033343
private function arrayFilterRecursive(array &$array)
    {
        foreach ($array as $key => &$item) {
            is_array($item) && $array[$key] = $this->arrayFilterRecursive($item);
            if ($array[$key] === null ||
                $array[$key] === []
            ) {
                unset($array[$key]);
            }
        }
        return $array;
    }
119724
public static function sGet($array, $key, $default = null)
    {
        $value = self::get($array, $key);
        return !empty($value) ? $value : $default;
    }
418692
protected function _checkPcrePattern($pattern = null) {
		if (empty($pattern)) {
			return null;
		}

		$result = true;
		try {
			//@codingStandardsIgnoreStart
			$matchResult = @preg_match($pattern, 'some text');
			//@codingStandardsIgnoreEnd
			if ($matchResult === false) {
				$result = false;
			}
		} catch (Exception $exception) {
			$result = false;
		}

		return $result;
	}
1179318
public function regex($array = [])
    {
        $filtered = [];
        foreach ($array as $key => $value) {
            if ($this->isRegex($key)) {
                $filtered[$key] = $value;
            }
        }

        return $filtered;
    }
1203295
protected function processPattern(array $patterns)/*# : array */
    {
        $result = [];
        foreach ($patterns as $pat) {
            $part = explode('/', $pat);
            $addr = ip2long($part[0]);
            $mask = isset($part[1]) ? ((int) $part[1]) : 32;

            // fix
            $mask = $this->getMask($mask);
            $addr = $addr & $mask;

            $result[] = [$addr, $mask];
        }
        return $result;
    }