本文整理汇总了PHP中ArrayUtil::findMean方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtil::findMean方法的具体用法?PHP ArrayUtil::findMean怎么用?PHP ArrayUtil::findMean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayUtil
的用法示例。
在下文中一共展示了ArrayUtil::findMean方法的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: testFindMeanWithMultipleElementsArray
/**
* @depends testFindMeanWithSingleElementArray
*/
public function testFindMeanWithMultipleElementsArray()
{
$mean = ArrayUtil::findMean(array(1, 4, 5, 7));
$this->assertEquals(4.25, $mean);
}