3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php error_reporting(0); $results = array(); for($i = 0; $i < 10000; $i++) { $results[] = (object) rand(0, 100000); } $start = microtime(true); for($i = 0; $i < 1000; $i++) { $alreadyOutput = array(); foreach ($results as $result) { if(in_array($result->date, $alreadyOutput)){ continue; } $alreadyOutput[] = $result->date; } } echo "in_array: ".(microtime(true) - $start)."ms || "; $start2 = microtime(true); for($i = 0; $i < 1000; $i++) { $echoedArray = array(); foreach ($results as $result) { if ($echoedArray[$result->date]) { continue; } $echoedArray[$result->date] = true; } } echo "by key: ".(microtime(true) - $start2)."ms";
based on FrgnN
Output for 7.1.0
in_array: 2.1887409687042ms ||
Process exited with code 137.
Output for 7.0.14
in_array: 2.2460691928864ms ||
Process exited with code 137.
Output for 7.0.6
in_array: 2.3990919589996ms ||
Process exited with code 137.
Output for 7.0.5
in_array: 2.2436730861664ms ||
Process exited with code 137.
Output for 7.0.4
in_array: 2.2440919876099ms ||
Process exited with code 137.
Output for 7.0.3
in_array: 2.2589280605316ms ||
Process exited with code 137.
Output for 7.0.2
in_array: 2.2970550060272ms ||
Process exited with code 137.
Output for 7.0.1
in_array: 2.4009039402008ms ||
Process exited with code 137.
Output for 7.0.0
in_array: 2.2958719730377ms ||
Process exited with code 137.
Output for hhvm-3.12.0
in_array: 1.8330030441284ms ||
Process exited with code 137.
Output for 5.3.9 - 5.6.28, hhvm-3.10.0

Process exited with code 137.