3v4l.org

run code in 300+ PHP versions simultaneously
<?php function delete(array &$array, string $key): bool { // process the parts $target =& $array; // split the key in it's parts $key_parts = explode('.', $key); while (true) { // check if this key exists, and bail out if it doesn't if ( ! array_key_exists($key_parts[0], $target)) { return false; } // last key component? if (count($key_parts) === 1) { // delete the target found unset($target[$key_parts[0]]); return true; } // change the target $target =& $target[$key_parts[0]]; // and on to the next key part array_shift($key_parts); } } $arr = array('a' => array('b1' => array('c1' => 'value c1', 'c2' => 'value c2'), 'b2' => 'value b2')); var_dump(delete($arr, 'a.b1.c1'), $arr);
Output for git.master, git.master_jit, rfc.property-hooks
bool(true) array(1) { ["a"]=> array(2) { ["b1"]=> array(1) { ["c2"]=> string(8) "value c2" } ["b2"]=> string(8) "value b2" } }

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