/* filterBySchema might be better, to decide delete this later (TODO)
merge and intersec array with schema
@param table, $array
@return array of assoc
967265
public static function schemaBasedArray($tname, $iArray) {

        if (empty($tname) or empty($iArray)) return array();
        
        $fields = self::fieldsKey($tname);
        $carray = array_merge(array_flip($fields), $iArray);
        return self::aIntersec($carray, $fields);
    }
871891
private function isAssoc($array) {
	$allIntegerKeys = true;
	foreach ($array as $key => $value) {
		if(!is_integer($key)) {
			$allIntegerKeys = false;
			break;
		}
	}

	return $allIntegerKeys === false;
}
733834
public function filter($table)
    {
        foreach ($table->getRows() as $key => $row) {
            $params = array();
            foreach ($this->columnsToFilter as $column) {
                $params[] = $row->getColumn($column);
            }

            $params = array_merge($params, $this->functionParams);
            if (call_user_func_array($this->function, $params) === true) {
                $table->deleteRow($key);
            }

            $this->filterSubTable($row);
        }
    }
5134
public function filter(&$array) {
        while(list($key, $var) = each($array)) {
            if ($key != 'argc' && $key != 'argv' && (strtoupper($key) != $key || '' . intval($key) == "$key")) {
                if (is_string($var)) {
                    $array[$key] = stripslashes($var);
                }
                if (is_array($var))  {
                    $array[$key] = $this->filter($var);
                }
            }
        }
        return $array;
    }
776918
public function arrayFilterRecursive(array $array)
    {
        foreach ($array as &$value) {
            if (is_array($value)) {
                /** @var $value array */
                $value = count($value) === 1 && array_key_exists(0, $value) && is_string($value[ 0 ]) &&
                $this->variable->isEmpty(trim($value[ 0 ])) ? $value[ 0 ] : $this->arrayFilterRecursive($value);
            }
        }

        return array_filter($array, function ($value) {
            return ! $this->variable->isEmpty($value) &&
                ! (is_string($value) && $this->variable->isEmpty(trim($value)));
        });
    }
113533
public function arrayChangeCaseKey($array)
    {
        return array_map(function ($item) {
            if (is_array($item)) {
                $item = $this->arrayChangeCaseKey($item);
            }

            return $item;
        }, array_change_key_case($array));
    }
268040
public function filter($table)
    {
        $table->setMetadata(DataTable::TOTAL_ROWS_BEFORE_LIMIT_METADATA_NAME, $table->getRowsCount());

        if ($this->keepSummaryRow) {
            $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);
        }

        // we delete from 0 to offset
        if ($this->offset > 0) {
            $table->deleteRowsOffset(0, $this->offset);
        }
        // at this point the array has offset less elements. We delete from limit to the end
        if ($this->limit >= 0) {
            $table->deleteRowsOffset($this->limit);
        }

        if ($this->keepSummaryRow && !empty($summaryRow)) {
            $table->addSummaryRow($summaryRow);
        }
    }
377895
public static function array_filter_values($array, $c = null)
    {
        if (isset($c['with'])) {

            $data = array();

            foreach ($array as $key => $value) {
                if (strpos($value, $c['with'])) {
                    $data[$key] = $value;
                }
            }

            return $data;
        } else {
            return array_filter($array);
        }
    }
611813
public function filter($table)
    {
        foreach ($table->getRows() as $row) {
            $extraColumnParameters = array();
            foreach ($this->extraColumnParameters as $columnName) {
                $extraColumnParameters[] = $row->getColumn($columnName);
            }

            foreach ($this->columnsToFilter as $column) {

                // when a value is not defined, we set it to zero by default (rather than displaying '-')
                $value = $this->getElementToReplace($row, $column);
                if ($value === false) {
                    $value = 0;
                }

                $parameters = array_merge(array($value), $extraColumnParameters);

                if (!is_null($this->functionParameters)) {
                    $parameters = array_merge($parameters, $this->functionParameters);
                }

                $newValue = call_user_func_array($this->functionToApply, $parameters);
                $this->setElementToReplace($row, $column, $newValue);
                $this->filterSubTable($row);
            }
        }

        if (in_array('label', $this->columnsToFilter)) {
            // we need to force rebuilding the index
            $table->setLabelsHaveChanged();
        }
    }
80310
public static function arrayToMask($array)
    {
        $mask = self::NONE_MASK;

        if (empty($array) || !is_array($array)) {
            return $mask;
        }

        foreach ($array as $verb) {
            switch ($verb) {
                case self::GET:
                    $mask |= self::GET_MASK;
                    break;
                case self::POST:
                    $mask |= self::POST_MASK;
                    break;
                case self::PUT:
                    $mask |= self::PUT_MASK;
                    break;
                case self::PATCH:
                    $mask |= self::PATCH_MASK;
                    break;
                case self::DELETE:
                    $mask |= self::DELETE_MASK;
                    break;
                case self::OPTIONS:
                    $mask |= self::OPTIONS_MASK;
                    break;
                case self::HEAD:
                    $mask |= self::HEAD_MASK;
                    break;
                case self::COPY:
                    $mask |= self::COPY_MASK;
                    break;
                case self::TRACE:
                    $mask |= self::TRACE_MASK;
                    break;
                case self::CONNECT:
                    $mask |= self::CONNECT_MASK;
                    break;
            }
        }

        return $mask;
    }
1348608
public function filterArray($array)
    {
        $newArray = array();

        foreach ($array as $key => $row) {
            foreach ($this->columnToFilter as $column) {
                if (!array_key_exists($column, $row)) {
                    continue;
                }

                if (self::match($this->patternToSearchQuoted, $row[$column], $this->invertedMatch)) {
                    $newArray[$key] = $row;
                    continue 2;
                }
            }
        }

        return $newArray;
    }
187419
public static function filterBySchema($tname, $iArray) {

        try {    
            $fields = self::schema($tname,"_none_");
            // diff in array with schma fields
            $diffs = array_diff_key($iArray, $fields);
            // remove unwanted fields
            foreach ($diffs as $k=>$v) {
                unset($iArray[$k]);
            }
            return $iArray;    
        } catch (Exception $e) {
            echo $e->getTraceAsString();
        }        
                    
    }
527191
public static function array_filter_keys($array, $params = null)
    {

        $array = self::toArray($array);

        $isMultidimensionnal = self::is_multi($array);

        if (is_string($params)) {
            $params = array('with' => $params);
        }

        if (isset($params['with'])) {
            $data = array();

            if (!$isMultidimensionnal) {
                foreach ($array as $key => $value) {
                    if (preg_match('/' . $params['with'] . '/i', $key)) {
                        $data[] = $value;
                    }
                }
            } else {
                foreach ($array as $v1) {
                    foreach ($v1 as $key => $value) {
                        if (preg_match('/' . $params['with'] . '/i', $key)) {
                            $data[] = $value;
                        }
                    }
                }
            }

            return $data;
        }

        return array_filter($array);

    }
748090
public function filter(Table $table)
    {
        $this->sqlAnds = [];
        $this->sqlParams = $this->initialParams;

        $columns = $table->getColumns();
        foreach ($table->getFilters() as $column => $filterData) {
            foreach ($filterData as $name => $value)
                $this->buildFilter($columns[$column]['sql_id'], $columns[$column]['type'], $name, $value);
        }

        return $this;
    }
977839
protected function filter(array $array)
    {
        $config = collect(array_dot($array))->map(function ($value, $key) {
            if (str_contains($key, $this->hidden)) {
                return '';
            }

            if (in_array($key, $this->boolean)) {
                return (bool) $value;
            }

            return $value;
        });

        $array = [];
        foreach ($config as $key => $value) {
            array_set($array, $key, $value);
        }

        return $array;
    }
866770
private function filterDuplicates($array)
    {
        $result = [];
        foreach ($array as $value) {
            if (!in_array($value, $result)) {
                $result[] = $value;
            }
        }
        return array_filter($result);
    }
934894
public function filter($table)
    {
        foreach ($table->getRows() as $key => $row) {
            //instead search must handle
            // - negative search with -piwik
            // - exact match with ""
            // see (?!pattern) 	A subexpression that performs a negative lookahead search, which matches the search string at any point where a string not matching pattern begins.
            $value = $row->getColumn($this->columnToFilter);
            if ($value === false) {
                $value = $row->getMetadata($this->columnToFilter);
            }
            if (!self::match($this->patternToSearchQuoted, $value, $this->invertedMatch)) {
                $table->deleteRow($key);
            }
        }
    }