3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Fish {} class Mammal {} class Whale extends Mammal {} class Human extends Mammal {} class Shark extends Fish {} // Not very exceptional... class FoundException extends Exception {} function anyFish(array $collection) { $found = false; try { array_walk_recursive($collection, function ($v) { if($v instanceof Fish) throw new FoundException('I found a fish.'); }); } catch (FoundException $e) { $found = true; } return $found; } $seas = [ 'pacific' => [new Whale, new Shark], 'atlantic' => [new Human, new Shark] ]; $pub = [new Human, new Human]; var_dump(anyFish($seas)); var_dump(anyFish($pub));

preferences:
29.59 ms | 402 KiB | 5 Q