3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $id; public function __construct(){ static $counter = 0; $this->id = $counter; ++$counter; } } $collection = [new Foo(), new Foo(), new Foo(), new Foo()]; print_r(array_column($collection, 'id'));

preferences:
23.05 ms | 405 KiB | 5 Q