3v4l.org

run code in 300+ PHP versions simultaneously
<?php $vyvoj_cien = array( 0 => 100, 1 => 110, 2 => 120, 3 => 130, 4 => 140, 5 => 150, 6 => 160, 7 => 170, 8 => 180, 9 => 190, 10 => 200, 11 => 185, 12 => 175, 13 => 165, 14 => 160, 15 => 160, 16 => 160, 17 => 160, 18 => 160, 19 => 160, ); // jednoduchy priemer function sma(array $data) { $count = count($data); if (!$count) $count = 1; return array_sum($data) / $count; } // exponencialny priemer function ema(array $data,$return_last_only = true) { $data = array_values($data); // preindexovanie pola ak by nahodou boli nejake kluce vynechane a pod. $multiplier = 2 / (1 + count($data)); for ($i=0; $i<count($data); $i++) { $prev = isset($data[$i-1]) ? $data[$i-1] : $data[$i]; $data[$i] = $data[$i] * $multiplier + $prev * (1 - $multiplier); } return $return_last_only ? end($data) : $data; } // dvojity exponencialny priemer function dema(array $data,$return_last_only = true) { $data = array_values($data); // preindexovanie pola ak by nahodou boli nejake kluce vynechane a pod. $ema1 = ema($data,false); $ema2 = ema($ema1,false); for ($i=0; $i<count($data); $i++) { $data[$i] = 2 * $ema1[$i] - $ema2[$i]; } return $return_last_only ? end($data) : $data; } // trojity exponencialny priemer function tema(array $data,$return_last_only = true) { $data = array_values($data); // preindexovanie pola ak by nahodou boli nejake kluce vynechane a pod. $ema1 = ema($data,false); $ema2 = ema($ema1,false); $ema3 = ema($ema2,false); for ($i=0; $i<count($data); $i++) { $data[$i] = (3*$ema1[$i] - 3*$ema2[$i]) + $ema3[$i]; } return $return_last_only ? end($data) : $data; } ///// VYSLEDKY ///// echo "Zdrojove data: " . implode(', ', $vyvoj_cien) . PHP_EOL; echo "Jednoduchy priemer dat: " . sma($vyvoj_cien) . PHP_EOL;

preferences:
29.95 ms | 402 KiB | 5 Q