3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* assuming top level pid = 0 */$rows = array ( array ( 'id' => 1, 'pid' => 0 ), array ( 'id' => 2, 'pid' => 1 ), array ( 'id' => 3, 'pid' => 2 ), array ( 'id' => 4, 'pid' => 0 ), array ( 'id' => 5, 'pid' => 4 ), /* ... */);$rows = array_column ( $rows, null, 'id' );foreach ( $rows as $key => $val ) { if ( $val ['pid'] ) { if ( isset ( $rows [$val ['pid']] )) { $rows [$val ['pid']]['children'][] = &$rows [$key]; } }}foreach ( $rows as $key => $val ) { if ( $val ['pid'] ) unset ( $rows [$key] );}var_dump ( $rows );
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { [1]=> array(3) { ["id"]=> int(1) ["pid"]=> int(0) ["children"]=> array(1) { [0]=> array(3) { ["id"]=> int(2) ["pid"]=> int(1) ["children"]=> array(1) { [0]=> array(2) { ["id"]=> int(3) ["pid"]=> int(2) } } } } } [4]=> array(3) { ["id"]=> int(4) ["pid"]=> int(0) ["children"]=> array(1) { [0]=> array(2) { ["id"]=> int(5) ["pid"]=> int(4) } } } }

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:
59.6 ms | 402 KiB | 8 Q