3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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;
Output for 5.1.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Zdrojove data: 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 185, 175, 165, 160, 160, 160, 160, 160, 160 Jednoduchy priemer dat: 156.75
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/KumPO on line 28
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/KumPO on line 28
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/KumPO on line 28
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/KumPO on line 28
Process exited with code 255.