3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array = array('a', 'b', 'c', 'd', 'e', 'f', 'g'); function nestArray($arr) { if(empty($arr)) { return array(); } return array(array_shift($arr) => nestArray($arr)); } var_dump(nestArray($array));
based on 7AjAJ
Output for 4.3.0 - 7.1.0
array(1) { ["a"]=> array(1) { ["b"]=> array(1) { ["c"]=> array(1) { ["d"]=> array(1) { ["e"]=> array(1) { ["f"]=> array(1) { ["g"]=> array(0) { } } } } } } } }