3v4l.org

run code in 300+ PHP versions simultaneously
<?php function facdef($n) { switch($n) { case 0: return 1; case 1: return 1; case 2: return 2; case 3: return 6; case 4: return 24; case 5: return 120; case 6: return 720; case 7: return 5040; case 8: return 40320; case 9: return 362880; case 10: return 3628800; case 11: return 39916800; case 12: return 479001600; case 13: return 6227020800; case 14: return 87178291200; case 15: return 1307674368000; case 16: return 20922789888000; case 17: return 355687428096000; case 18: return 6402373705728000; case 19: return 121645100408832000; case 20: return 2432902008176640000; case 21: return 51090942171709440000; case 22: return 1124000727777607680000; case 23: return 25852016738884976640000; } } function constify($a) { #regression constants return $a*0.424+0.548; } function scorefix($avg) { #if predicted score is small or negative, return something reasonable if ( $avg < 0.01 ) { return pow(10,(pow(10,$avg-1))) / 105.50984676065602; } else { return $avg; } } function sim($homeoff,$homedef,$awayoff,$awaydef,$mul,$natavg) { #returns homemu,awaymu for poisson to deal with return array(scorefix((($homeoff-$natavg)*max(constify($awaydef*$mul),0.25)/constify($natavg*$mul)+$awaydef)*$mul),scorefix((($homedef-$natavg)*max(constify($awayoff/$mul),0.25)/constify($natavg/$mul)+$awayoff)/$mul)); } function poisson($mu,$shift) { #returns array of poisson probabilities for scores $x = []; for ($i = 1 ; $i <= $shift ; $i++ ) { array_push($x,0.0); } $pcdf = 0.0; $a = exp(-1*$mu); echo count($a); while ( $pcdf < 0.999999 || count($x) < 5 ) { echo pow($mu,(count($x)-$shift))."\n"; echo facdef(count($x)-$shift)."\n"; array_push($x,$a*(pow($mu,(count($x)-$shift)))/facdef(count($x)-$shift)); echo count($x); $pcdf+=end($x); } return $x; } var_dump(poisson(1.1,0)); ?>
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, float given in /in/k7dXn:75 Stack trace: #0 /in/k7dXn(86): poisson(1.1, 0) #1 {main} thrown in /in/k7dXn on line 75
Process exited with code 255.
Output for 8.0.0 - 8.0.9
Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, float given in /in/k7dXn:75 Stack trace: #0 /in/k7dXn(86): poisson(1.1, 0) #1 {main} thrown in /in/k7dXn on line 75
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: count(): Parameter must be an array or an object that implements Countable in /in/k7dXn on line 75 11 1 11.1 1 21.21 2 31.331 6 41.4641 24 51.61051 120 61.771561 720 71.9487171 5040 82.14358881 40320 92.357947691 362880 10array(10) { [0]=> float(0.33287108369808) [1]=> float(0.36615819206789) [2]=> float(0.20138700563734) [3]=> float(0.073841902067024) [4]=> float(0.020306523068432) [5]=> float(0.004467435075055) [6]=> float(0.00081902976376007) [7]=> float(0.0001287046771623) [8]=> float(1.7696893109816E-5) [9]=> float(2.1629536023108E-6) }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
11 1 11.1 1 21.21 2 31.331 6 41.4641 24 51.61051 120 61.771561 720 71.9487171 5040 82.14358881 40320 92.357947691 362880 10array(10) { [0]=> float(0.33287108369808) [1]=> float(0.36615819206789) [2]=> float(0.20138700563734) [3]=> float(0.073841902067024) [4]=> float(0.020306523068432) [5]=> float(0.004467435075055) [6]=> float(0.00081902976376007) [7]=> float(0.0001287046771623) [8]=> float(1.7696893109816E-5) [9]=> float(2.1629536023108E-6) }

preferences:
230.03 ms | 403 KiB | 330 Q