3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php error_reporting(0); $amount = 50000; $start = microtime(true); $alreadyOutput = array(); $iterator = $amount; while ($iterator --) { $num = rand(0, $amount); if(in_array($num, $alreadyOutput)){ continue; } $alreadyOutput[] = $num; } echo "in_array: ".(microtime(true) - $start)."ms || "; unset($alreadyOutput); $alreadyOutput = array(); $start2 = microtime(true); $iterator = $amount; while ($iterator --) { $num = rand(0, $amount); if(isset($alreadyOutput[$num])){ continue; } $alreadyOutput[$num] = true; } echo "by key: ".(microtime(true) - $start2)."ms";
based on uFUbH
Output for 7.1.0
in_array: -0.48404407501221ms || by key: -0.0049939155578613ms
Output for 7.0.14
in_array: 0.91905903816223ms || by key: 0.0046939849853516ms
Output for 7.0.6
in_array: 0.89798593521118ms || by key: 0.0053441524505615ms
Output for 7.0.5
in_array: 0.89937400817871ms || by key: 0.0053069591522217ms
Output for 7.0.4
in_array: 0.85292196273804ms || by key: 0.0048279762268066ms
Output for 7.0.3
in_array: 0.86746907234192ms || by key: 0.0047969818115234ms
Output for 7.0.2
in_array: 1.0542080402374ms || by key: 0.0054559707641602ms
Output for 7.0.1
in_array: 0.84158086776733ms || by key: 0.0049328804016113ms
Output for 7.0.0
in_array: 0.82090997695923ms || by key: 0.0048108100891113ms
Output for 5.3.9 - 5.3.16, 5.3.18 - 5.6.28

Process exited with code 137.
Output for 5.3.17

Process exited with code 143.