3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmark(string $name, callable $callback) { $string = ')(8234@#$ABCFG3478&* hello'; $time = microtime(true); for ($i = 0; $i < 500_000; ++$i) { $callback($string); } $time = microtime(true) - $time; echo number_format($time, 6), 's: ', $name, ' (result: ', $callback($string), ")\n"; } benchmark('preg', function (string $string) { $firstLetter = null; if (preg_match('/[a-z0-9]/i', $string, $match)) { $firstLetter = $match[0]; } return $firstLetter; }); benchmark('ctype_alnum', function (string $string) { $length = strlen($string); $firstLetter = null; for ($i = 0; $i < $length; ++$i) { if (ctype_alnum($string[$i])) { $firstLetter = $string[$i]; break; } } return $firstLetter; }); benchmark('strcspn', function (string $string) { return $string[strcspn($string, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")] ?? null; });

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
160.43 ms | 1375 KiB | 18 Q