3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $test; private $counter = 0; public function __construct() { $this->test = array('a', 'b', 'c'); } public function getBar() { return $this->test[$this->counter++]; } } $array = array(); $foo = new Foo(); foreach (range(0, 3) as $key) { $array[$foo->getBar()] = $key; } print_r($array);

preferences:
36.65 ms | 402 KiB | 5 Q