public function toArray() { $list = parent::toArray(); foreach ($list as $key => $value) { if ($value instanceof self) { $list[$key] = $value->toArray(); } } return $list; }
public function testGet() { $elements = [1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0]; $collection = new ArrayCollection($elements); $this->assertSame(2, $collection->get(1), 'Get element by index'); $this->assertSame('a', $collection->get('A'), 'Get element by name'); $this->assertSame(null, $collection->get('non-existent'), 'Get non existent element'); }