3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public $test = []; public function __construct() { $this->test['foo'] = 'foo'; $this->test['bar'] = 'bar'; } public function getTest(): array { return $this->test; } } $test = new Test; foreach($test->getTest() as $key => $value) { if ($key === 'foo') { $test->test['baz'] = 'baz'; } var_dump($value); }

preferences:
55.64 ms | 402 KiB | 5 Q