3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php/** * Compare building an array an in_array()ing it, vs a regex check */$runs = 1000000;// in_array$t = microtime(true);for ($i = 0; $i < $runs; $i++) { if (in_array('test', ['foo','bar','baz','fooby','bario','xyz','abc','def','ghi','jkl','mno','pqr','stu','vwx']));}$t -= microtime(true);echo 'in_array: ', $t, PHP_EOL;// preg_match$t = microtime(true);for ($i = 0; $i < $runs; $i++) { if (preg_match('/^(foo|bar|baz|fooby|bario|xyz|abc|def|ghi|jkl|mno|pqr|stu|vwx)$/', 'test'));}$t -= microtime(true);echo 'preg_match: ', $t, PHP_EOL;<?php
Output for 5.4.0 - 5.5.15
Parse error: syntax error, unexpected '$runs' (T_VARIABLE) in /in/BZR03 on line 1
Process exited with code 255.
Output for 4.3.0 - 5.3.29
<?php/** * Compare building an array an in_array()ing it, vs a regex check */$runs = 1000000;// in_array$t = microtime(true);for ($i = 0; $i < $runs; $i++) { if (in_array('test', ['foo','bar','baz','fooby','bario','xyz','abc','def','ghi','jkl','mno','pqr','stu','vwx']));}$t -= microtime(true);echo 'in_array: ', $t, PHP_EOL;// preg_match$t = microtime(true);for ($i = 0; $i < $runs; $i++) { if (preg_match('/^(foo|bar|baz|fooby|bario|xyz|abc|def|ghi|jkl|mno|pqr|stu|vwx)$/', 'test'));}$t -= microtime(true);echo 'preg_match: ', $t, PHP_EOL;<?php