src/Utilities/Regex.php
public static function arrayFilter($array, $arrayColumnKey, $filterExpression, $itsRegularExpression = false)
    {
        /*
         * No elements?
         * Nothing to do
         */
        if (empty($array)) {
            return [];
        }

        $effect = $array;

        foreach ($effect as $key => &$item) {
            if (!isset($item[$arrayColumnKey])) {
                continue;
            }

            $value = $item[$arrayColumnKey];

            if ($itsRegularExpression) {
                $matchesCount = preg_match($filterExpression, $value);
                $remove = 0 === $matchesCount;
            } else {
                if (is_string($value)) {
                    $value = sprintf('\'%s\'', $value);
                } elseif (is_bool($value)) {
                    if (true === $value) {
                        $value = 'true';
                    } else {
                        $value = 'false';
                    }
                }

                eval(sprintf('$isEqual = %s%s;', $value, $filterExpression));

                /** @var bool $isEqual */
                $remove = !$isEqual;
            }

            if ($remove) {
                unset($effect[$key]);
            }
        }

        return $effect;
    }
public static function arrayFilter($array, $arrayColumnKey, $filterExpression, $itsRegularExpression = false)
    {
        /*
         * No elements?
         * Nothing to do
         */
        if (empty($array)) {
            return [];
        }

        $effect = $array;

        foreach ($effect as $key => &$item) {
            if (!isset($item[$arrayColumnKey])) {
                continue;
            }

            $value = $item[$arrayColumnKey];

            if ($itsRegularExpression) {
                $matchesCount = preg_match($filterExpression, $value);
                $remove = 0 === $matchesCount;
            } else {
                if (is_string($value)) {
                    $value = sprintf('\'%s\'', $value);
                } elseif (is_bool($value)) {
                    if (true === $value) {
                        $value = 'true';
                    } else {
                        $value = 'false';
                    }
                }

                eval(sprintf('$isEqual = %s%s;', $value, $filterExpression));

                /** @var bool $isEqual */
                $remove = !$isEqual;
            }

            if ($remove) {
                unset($effect[$key]);
            }
        }

        return $effect;
    }
public static function arrayFilter ( $ array , $ arrayColumnKey , $ filterExpression , $ itsRegularExpression = false ) { /*
         * No elements?
         * Nothing to do
         */ if ( empty ( $ array ) ) { return [ ] ; } $ effect = $ array ; foreach ( $ effect as $ key => & $ item ) { if ( ! isset ( $ item [ $ arrayColumnKey ] ) ) { continue ; } $ value = $ item [ $ arrayColumnKey ] ; if ( $ itsRegularExpression ) { $ matchesCount = preg_match ( $ filterExpression , $ value ) ; $ remove = 0 === $ matchesCount ; } else { if ( is_string ( $ value ) ) { $ value = sprintf ( '\'%s\'' , $ value ) ; } elseif ( is_bool ( $ value ) ) { if ( true === $ value ) { $ value = 'true' ; } else { $ value = 'false' ; } } eval ( sprintf ( '$isEqual = %s%s;' , $ value , $ filterExpression ) ) ; /** @var bool $isEqual */ $ remove = ! $ isEqual ; } if ( $ remove ) { unset ( $ effect [ $ key ] ) ; } } return $ effect ; }
Filters array by given expression and column

Expression can be simple compare expression, like " == 2", or regular expression.
Returns filtered array.

@param array  $array                The 2-dimensional array that should be filtered
@param string $arrayColumnKey       Column name
@param string $filterExpression     Simple filter expression (e.g. "== 2" or "!= \'home\'") or regular
expression (e.g. "/\d+/" or "/[a-z]+[,;]{2,}/")
@param bool   $itsRegularExpression (optional) If is set to true, means that filter expression is a regular
expression. Otherwise - not (default behaviour).
@return array
Filters array by given expression and column