3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringPathAccess { protected $data = array(); public function __construct(array $data) { $this->data = $data; } public function &get($key) { if (strpos($key, '[]') !== false) { $key = str_replace('[]', '', $key); } $parts = explode('[', $key); $value = &$this->data; foreach ($parts as $part) { $part = rtrim($part, ']'); if (isset($value[$part])) { $value = &$value[$part]; } else { return null; } } return $value; } public function set($key, $value) { $val = &$this->get($key); $val = $value; } } $data = array( 'foo' => array( 'bar' => 'baz' )); $object = new StringPathAccess($data); $test = $object->get('foo[bar]'); var_dump($object->get('foo[bar]')); $object->set('foo[bar]', 'Hello World'); var_dump($object->get('foo[bar]'));
Output for git.master, git.master_jit, rfc.property-hooks
string(3) "baz" string(11) "Hello World"

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:
55.12 ms | 401 KiB | 8 Q