remove duplicate Entries and Count

@param array $arrDev list of HWDevices

@see HWDevice

@return array
10726
public static function removeDupsAndCount($arrDev)
    {
        $result = array();
        foreach ($arrDev as $dev) {
            if (count($result) === 0) {
                array_push($result, $dev);
            } else {
                $found = false;
                foreach ($result as $tmp) {
                    if ($dev->equals($tmp)) {
                        $tmp->setCount($tmp->getCount() + 1);
                        $found = true;
                        break;
                    }
                }
                if (!$found) {
                    array_push($result, $dev);
                }
            }
        }

        return $result;
    }
527528
private function filterArray($arrData, $arrFilters) {
		// Normalize the filter array (['filter' => FILTER, ...])
		foreach ($arrFilters as $key => &$F) {
			if (is_int($F))
				$F = array('filter' => $F);

			elseif (!isset($F['filter'])) {
				unset($arrFilters[$key]);
				continue;

			} elseif (is_string($F['filter'])) {
				try {
					$intF = @constant($F['filter']);
				} catch (\Exception $e) {
					continue;
				}
				if ( $intF )
					$F['filter'] = $intF;
				else {
					continue;

				}
			} elseif (isset($F['required'])) {
				if (!$F['required'] && (string)$arrData[$key] == '') {
					unset($arrFilters[$key]);
					continue;
				}
			}

			$F['value'] = isset($arrData[$key]) ? $arrData[$key] : null;
			if (!isset($F['field']))
				$F['field'] = $key;
		}

		$arrCallbacks = array();
		$arrValidators = array();

		// Remove callback functions from the filter array and allocate them to the callback array
		foreach ($arrFilters as $key => $filter) {
			if (isset($this->filters[$filter['filter']])) {
				$arrValidators[$key] = $filter + $this->filters[$filter['filter']];
				$arrValidators[$key]['filter'] = $this->filters[$filter['filter']]['filter'];
			} elseif (isset($this->callbacks[$filter['filter']]))
				$arrCallbacks[$key] = $filter;
			else
				$arrValidators[$key] = $filter;
		}

		$validate = array();

		// Validate the callbacks
		foreach ($arrCallbacks as $key => $filter)
			$validate[$key] = call_user_func($this->callbacks[$filter['filter']], $filter);

		// Validate through PHP filter function
		$validate = $validate + filter_var_array($arrData, $arrValidators);

		// Check the results
		$res = array();
		foreach ($arrFilters as $key => $filter) {
			$result = isset($validate[$key]) ? $validate[$key] : null;
			if (is_null($result) || ($filter != FILTER_VALIDATE_BOOLEAN && (bool) $result == false))
				$res[$key] = $filter;
		}

		return $res;
	}
795807
public static function reIndex($arr)
	{
		// reindex this level
		$arr = array_merge($arr);

		foreach ($arr as &$v)
		{
			is_array($v) and $v = static::reIndex($v);
		}

		return $arr;
	}
800312
public static function filter_keys($arr, $keys)
    {
        foreach ($arr as $key => $v) {
            if (!in_array($key, $keys)) {
                unset($arr[$key]);
            }
        }

        return $arr;
    }
619852
protected function deleteExtraRecords()
    {
        try {
            $limit = (int)($this->limitMax);
        } catch (\Exception $ex) {
            Yii::error($ex->getMessage(), __METHOD__);
            return 0;
        }
        $host = $this->host;
         /* @var $host \rhosocial\user\User */
        $count = static::find()->createdBy($host)->count();
        Yii::info($host->getReadableGUID() . " has $count login logs.", __METHOD__);
        if ($count > $limit) {
            foreach (static::find()->createdBy($host)->orderByCreatedAt()->limit($count - $limit)->all() as $login) {
                /* @var $login static */
                $result = $login->delete();
                if (YII_ENV_DEV) {
                    Yii::info($host->getReadableGUID() . ": ($result) login record created at (" . $login->getCreatedAt() . ") was just deleted.", __METHOD__);
                }
            }
        }
        return $count - $limit;
    }
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;
    }
1358057
public static function arrayFromCamelToUnder($arrData)
    {
        $transformed = [];
        foreach ($arrData as $index => $data) {
            foreach ($data as $camelKey => $value) {
                $transformed[$index][self::unCamelize($camelKey)] = $value;
            }
        }
        return $transformed;
    }
770556
public static function arrayUnique(array $array)
    {
        // Serialize each array's value
        foreach ($array as &$value) {
            $value = serialize($value);
        }

        // Now remove duplicate strings
        $array = array_unique($array);

        // Now restore to its previous state with removed strings
        foreach ($array as &$value) {
            $value = unserialize($value);
        }

        return $array;
    }
683918
protected function removeRedundantParams(array $data): array
    {
        $data = array_filter($data, function ($item) {
            if ($item instanceof ArrayObject) {
                return $item->count() !== 0;
            }
            return !empty($item);
        });

        foreach ($data as $key => $value) {
            if (is_array($value) || $value instanceof ArrayObject) {
                $data[$key] = $this->removeRedundantParams($value);
            }
        }

        return $data;
    }
859066
protected function trimToRecurrenceCount(array $rrules, array $recurrenceEvents)
    {
        if (isset($rrules['COUNT'])) {
            $recurrenceCount = (intval($rrules['COUNT']) - 1);
            $surplusCount    = (sizeof($recurrenceEvents) - $recurrenceCount);

            if ($surplusCount > 0) {
                $recurrenceEvents  = array_slice($recurrenceEvents, 0, $recurrenceCount);
                $this->eventCount -= $surplusCount;
            }
        }

        return $recurrenceEvents;
    }
856068
protected function exist(Array $arr)
    {
        $return = [];

        foreach ($arr as $name) {
            $return[$name] = $this->have($name);
        }

        if (count($return) === 1) {
            return array_values($return)[0];
        }

        if (count($return) > 1) {
            return $return;
        }

        return null;
    }
229776
public static function unDot(array $array, $depth = INF): array
    {
        $results = [];

        foreach ($array as $key => $value) {
            if (count($dottedKeys = explode('.', (string) $key, 2)) > 1) {
                $results[$dottedKeys[0]][$dottedKeys[1]] = $value;
            } else {
                $results[$key] = $value;
            }
        }

        foreach ($results as $key => $value) {
            if (is_array($value) && ! empty($value) && $depth > 1) {
                $results[$key] = static::unDot($value, $depth - 1);
            }
        }

        return $results;
    }
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)));
        });
    }
936931
public static function array_idiff($arr1, $arr2) {
		// First off, a variable number of arguments can be passed.
		// Let's take a look and see what we have.
		$arrays = \func_get_args();
		if (! isset($arrays[1])) {
			return array();
		}
		foreach ($arrays as $a) {
			if (! \is_array($a)) {
				return array();
			}
		}

		// Compare the first to each.
		$length = \count($arrays);
		for ($x = 1; $x < $length; ++$x) {
			$common = array();

			// If the arrays are the same, or the second is empty,
			// we can skip the tests.
			if (! \count($arrays[$x])) {
				continue;
			}

			// Lowercase for comparison.
			$arr1 = mb::strtolower($arrays[0], true);
			$arr2 = mb::strtolower($arrays[$x], true);

			foreach ($arr1 as $k=>$v) {
				if (! \is_array($v) && ! \in_array($v, $arr2, true)) {
					$common[$k] = $arrays[0][$k];
				}
			}

			// Nothing left? The end!
			if (! \count($common)) {
				return $common;
			}

			$arrays[0] = $common;
		}

		return $arrays[0];
	}
1100135
public static function array_diff_multi($array1, $array2)
    {

        $res = array();
        foreach ($array1 as $entry) {
            if (!in_array($entry, $array2)) {
                $res[] = $entry;
            }
        }

        return $res;
    }
1176340
public function filterNullValuesFromArray(array $arr): array
    {
        foreach ($arr as $key => $value) {
            if ($value === null) {
                unset($arr[$key]);
            }
            if (is_array($value)) {
                $arr[$key] = $this->filterNullValuesFromArray($value);
            }
        }

        return $arr;
    }
1335839
public static function arrayCombine($arr1, $arr2)
    {
        $count = min(count($arr1), count($arr2));

        return array_combine(array_slice($arr1, 0, $count), array_slice($arr2, 0, $count));
    }