3v4l.org

run code in 300+ PHP versions simultaneously
<?php function example($reduced, $current) { if ($current === 'C') { throw new Exception("Cake!"); } $reduced[] = $current; return $reduced; }; try { $result = array_reduce(range('A', 'E'), 'example'); var_dump($result); } catch (Exception $e) { echo 'Exception: ' . $e->getMessage(); }

preferences:
40.97 ms | 402 KiB | 5 Q