3v4l.org

run code in 300+ PHP versions simultaneously
<?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;

preferences:
34.14 ms | 402 KiB | 5 Q