3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Collection implements IteratorAggregate { private $list = []; public function __construct(array $list = []) { $this->list = $list; } public function add(string $string): void { $this->list[] = $string; } public function getIterator(): Traversable { return new ArrayIterator($this->list); } public function map(callable $callback): self { return new static(array_map($callback, $this->list)); } public function each(callable $callback) { foreach ($this->list as $key => $item) { $this->list[$key] = $callback($item); } return $this; } } function generateArray(): array { return array_fill(0, 400000, 'test'); } $collection = new Collection(generateArray()); $collection->each(fn($value) => $value . 's'); var_dump($collection);

Abusive script

This script was stopped while abusing our resources


preferences:
28.97 ms | 406 KiB | 5 Q