3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tree = array(); $array = array(0=>array('tag'=>'one','level'=>1),1=>array('tag'=>'two','level'=>2),2=>array('tag'=>'three','level'=>3)); foreach($array as $v){ $level = $v['level']; if($level > 0){ $count[1] = count($tree); if($level === 1){ $tree[$count[1]]['tag'] = $v['tag']; } if($level > 1){ $count[2] = (isset($tree[$count[1]-1]['array']))?count($tree[$count[1]-1]['array']):0; if($level == 2){ $tree[$count[1]-1]['array'][$count[2]]['tag'] = $v['tag']; } if($level > 2){ $count[3] = (isset($tree[$count[1]-1]['array'][$count[2]-1]['array']))?count($tree[$count[1]-1]['array'][$count[2]-1]['array']):0; if($level == 3){ $tree[$count[1]-1]['array'][$count[2]-1]['array'][$count[3]]['tag'] = $v['tag']; } if($level > 3){ $count[4] = (isset($tree[$count[1]-1]['array'][$count[2]-1]['array'][$count[3]-1]['array']))?count($tree[$count[1]-1]['array'][$count[2]-1]['array'][$count[3]-1]['array']):0; if($level == 4){ $tree[$count[1]-1]['array'][$count[2]-1]['array'][$count[3]-1]['array'][$count[4]]['tag'] = $v['tag']; } } } } } } print_r($tree);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [tag] => one [array] => Array ( [0] => Array ( [tag] => two [array] => Array ( [0] => Array ( [tag] => three ) ) ) ) ) )

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:
40.56 ms | 1647 KiB | 4 Q