3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php final class RangesUtil { final private function __construct() {} /** * @param array $element * * @return int[] * Format: $[$value] = $count */ static function elementExtractUnsortedStats(array $element) { $rawStats = array(); foreach ($element as $value => $item) { if (isset($item['#count']) && is_int($item['#count'])) { $rawStats[$value] = $item['#count']; } } return $rawStats; } /** * @param float[]|int[] $steps * Format: $[] = $stepValue * @param int[] $ustats * (unsorted) stats. * Format: $[$value] = $count * @param bool $below * TRUE to accumulate below, FALSE to accumulate above. * @param bool $dedupe * * @return int[] * Format: $[$value] = $countAccum */ static function stepsUstatsAccumulate(array $steps, array $ustats, $below, $dedupe = FALSE) { $statsCombined = $ustats + array_fill_keys($steps, 0); ksort($statsCombined, SORT_NUMERIC); $statsCombinedAccum = self::statsAccumulate($statsCombined, $below); $stepsAccum = array(); foreach ($steps as $step) { $stepsAccum[$step] = $statsCombinedAccum[$step]; } if ($dedupe) { $stepsAccum = self::statsAccumDedupe($stepsAccum, $below); } return $stepsAccum; } /** * @param int[] $statsAccum * Format: $[$value] = $countAccum * @param bool $below * * @return int[] * Format: $[$value] = $countAccum */ static function statsAccumDedupe(array $statsAccum, $below) { $countPrev = NULL; foreach ($below ? $statsAccum : array_reverse($statsAccum, TRUE) as $value => $countAccum) { if ($countPrev === $countAccum) { unset($statsAccum[$value]); } } return $statsAccum; } /** * @param array $rawStats * * @return int[] * Format: $[$value] = $count */ static function unsortedStatsGetStats(array $rawStats) { ksort($rawStats, SORT_NUMERIC); return $rawStats; } /** * @param int[] $stats * (sorted) stats. * Format: $[$value] = $count * @param bool $below * TRUE to accumulate below, FALSE to accumulate above. * * @return int[] * Format: $[$value] = $countAccum */ static function statsAccumulate(array $stats, $below) { $total = 0; foreach ($below ? $stats : array_reverse($stats, TRUE) as $value => $count) { $total += $count; $stats[$value] = $total; } return $stats; } } $ustats = array( 0 => 2, 3 => 10, 7 => 100, 8 => 1000, 19 => 10000, ); $steps = array(0, 2, 5, 10, 20); var_export(RangesUtil::stepsUstatsAccumulate($steps, $ustats));
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function RangesUtil::stepsUstatsAccumulate(), 2 passed in /in/g07M3 on line 112 and at least 3 expected in /in/g07M3:37 Stack trace: #0 /in/g07M3(112): RangesUtil::stepsUstatsAccumulate(Array, Array) #1 {main} thrown in /in/g07M3 on line 37
Process exited with code 255.
Output for 5.3.21 - 7.0.20
Warning: Missing argument 3 for RangesUtil::stepsUstatsAccumulate(), called in /in/g07M3 on line 112 and defined in /in/g07M3 on line 37 Notice: Undefined variable: below in /in/g07M3 on line 40 array ( 0 => 11112, 2 => 11110, 5 => 11100, 10 => 10000, 20 => 0, )