3v4l.org

run code in 300+ PHP versions simultaneously
<?php $c = ['one'=>['two' =>['t' => false]]]; $p = explode('.', 'one.two.tree'); $v = true; $cf = &$c; // Look for the key, creating nested keys if needed while ($part = array_shift($p)) { if (!isset($cf[$part]) && count($p)) { $cf[$part] = array(); } $cf = &$cf[$part]; } $cf = $v; var_dump($cf, $c);

preferences:
45.25 ms | 402 KiB | 5 Q