本文整理匯總了PHP中ArrayUtil::findMedian方法的典型用法代碼示例。如果您正苦於以下問題:PHP ArrayUtil::findMedian方法的具體用法?PHP ArrayUtil::findMedian怎麽用?PHP ArrayUtil::findMedian使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ArrayUtil
的用法示例。
在下文中一共展示了ArrayUtil::findMedian方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: formatOutput
/**
* Format and echo output from extracted data
* @param $method
* @param $requestPath
* @param array $summary
*/
protected function formatOutput($method, $requestPath, array $summary)
{
// these 3 aren't really needed.
// here for:
// 1- To not give warnings in IDE about unknown variables
// 2- To set a default value, always a safer practice.
$dynos = array();
$totalOccurrences = 0;
$responseTimes = array();
extract($summary);
if (!$totalOccurrences) {
// not using die() as it causes issue with ob_*
echo "No occurrences of {$method} {$requestPath} found" . PHP_EOL;
return;
}
$mostCommonDyno = ArrayUtil::findModes($dynos);
$leastCommonDyno = ArrayUtil::findLeastCommonValues($dynos);
$meanResponseTime = ArrayUtil::findMean($responseTimes);
$medianResponseTime = ArrayUtil::findMedian($responseTimes);
$modeResponseTimes = ArrayUtil::findModes($responseTimes);
$minResponseTime = min($responseTimes);
$maxResponseTime = max($responseTimes);
$summary = <<<SUMMARY
Number of times request was made: %d
Most active Dyno(s): %s
Least active Dyno(s): %s
Min. Response Time: %d
Max. Response Time: %d
Mean Response Time: %f
Median Response Time: %f
Mode Response Time(s): %s
SUMMARY;
echo sprintf($summary, $totalOccurrences, implode(', ', $mostCommonDyno), implode(', ', $leastCommonDyno), $minResponseTime, $maxResponseTime, $meanResponseTime, $medianResponseTime, implode(', ', $modeResponseTimes));
}
示例2: testFindMedianWithOddNumberOfItemsArrays
/**
* @depends testFindMedianWithEvenNumberOfItemsArrays
*/
public function testFindMedianWithOddNumberOfItemsArrays()
{
$mean = ArrayUtil::findMedian(array(1, 4, 5));
$this->assertEquals(4, $mean);
}