public static function getMostFrequentValues(array $data, $mostFrequentQuantity = NULL, $allocationPeriod = NULL) { $mostFrequentValues = []; $allocatedData = self::allocateInfo($data, $allocationPeriod); usort($allocatedData, function ($a, $b) { if ($a->getValueQuantity() === $b->getValueQuantity()) { if ($a->getValue() === $b->getValueQuantity()) { return 0; } return $a->getValue() < $b->getValue() ? -1 : 1; } else { return $a->getValueQuantity() > $b->getValueQuantity() ? -1 : 1; } }); if (!$mostFrequentQuantity) { $mostFrequentQuantity = self::MOST_FREQUENT_QUANTITY; } for ($i = 0; $i < $mostFrequentQuantity; $i++) { $frequentValue = new SortData(); $frequentValue->setValue($allocatedData[$i]->getValue()); $frequentValue->setValueQuantity($allocatedData[$i]->getValueQuantity()); $valueExamples = $allocatedData[$i]->getValueExamples() !== "" ? substr($allocatedData[$i]->getValueExamples(), 0, -2) : $allocatedData[$i]->getValueExamples(); $frequentValue->setValueExamples($valueExamples); if ($mostFrequentQuantity === 1) { $mostFrequentValues = $frequentValue; } else { $mostFrequentValues[] = $frequentValue; } } return $mostFrequentValues; }