3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = new class() { public $callCounters = []; public function call($index) { $this->callCounters[$index] ?? 0; ++$this->callCounters[$index]; } }; $indexes = range('a','e'); foreach($indexes as $index) { $r = rand(1,4); for($i = 0; $i <= $r; ++$i) { $x->call($index); } } var_dump($x->callCounters);

preferences:
29.06 ms | 402 KiB | 5 Q