3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private $query; public function &findNode(array $path) { $link = &$this->query; foreach ($path as $element) { $link = &$link[$element]; } return $link; } public function setValues(array $path, array $values) { $node = &$this->findNode($path); $node = array_merge($node ?? [], $values); unset($node); return $this; } public function setValueByPath(array $path, $value): self { $link = &$this->findNode($path); if (is_array($value)) { $link[] = $value; } else { $link = $value; } unset($link); return $this; } public function print() { var_dump($this->query); } } $a = new A; $a ->setValues(['c', 'd'], [['test' => 1], ['test' => 2]]) ->setValues(['c', 'd'], [['test' => 3], ['test' => 4]]); $a ->setValueByPath(['a', 'b', 'c', 'd'], ['match' => 100500]) ->setValueByPath(['a', 'b', 'c', 'd'], ['match' => 1000]) ->setValueByPath(['a', 'b', 'c', 'd', 1, 'zzz'], 'lol'); print_r($a);
Output for git.master, git.master_jit, rfc.property-hooks
A Object ( [query:A:private] => Array ( [c] => Array ( [d] => Array ( [0] => Array ( [test] => 1 ) [1] => Array ( [test] => 2 ) [2] => Array ( [test] => 3 ) [3] => Array ( [test] => 4 ) ) ) [a] => Array ( [b] => Array ( [c] => Array ( [d] => Array ( [0] => Array ( [match] => 100500 ) [1] => Array ( [match] => 1000 [zzz] => lol ) ) ) ) ) ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
62.03 ms | 405 KiB | 8 Q