3v4l.org

run code in 300+ PHP versions simultaneously
<?php function retry($retries, callable $fn) { beginning: try { return $fn(); } catch (\Exception $e) { if (!$retries) { throw new \Exception('', 0, $e); } $retries--; goto beginning; } } $fn = function() { if (mt_rand(0, 5) === 0) { return true; } throw new \Exception('nope'); }; retry(10, $fn);

preferences:
32.75 ms | 402 KiB | 5 Q