<?php
$prices = array
(
'bar' => array(12.34, 102.55),
'foo' => array(12.34, 15.66, 102.55, 134.66),
'foobar' => array(12.34, 15.22, 14.18, 20.55, 99.50, 15.88, 16.99, 102.55),
);
foreach ($prices as $item => $bids)
{
$average = call_user_func_array('Average', $bids);
$standardDeviation = call_user_func_array('standardDeviation', $bids);
foreach ($bids as $key => $bid)
{
if (($bid < ($average - $standardDeviation)) || ($bid > ($average + $standardDeviation)))
{
unset($bids[$key]);
}
}
$prices[$item] = $bids;
}
print_r($prices);
function Average()
{
if (count($arguments = func_get_args()) > 0)
{
return array_sum($arguments) / count($arguments);
}
return 0;
}
function standardDeviation()
{
if (count($arguments = func_get_args()) > 0)
{
$result = call_user_func_array('Average', $arguments);
foreach ($arguments as $key => $value)
{
$arguments[$key] = pow($value - $result, 2);
}
return sqrt(call_user_func_array('Average', $arguments));
}
return 0;
}
?>