3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pages = array(); $pages[1] = array('id' => 1, 'parent' => 0, 'name' => 'Hello World'); $pages[2] = array('id' => 1, 'parent' => 1, 'name' => 'Child of Hello World'); $pages[3] = array('id' => 1, 'parent' => 0, 'name' => 'Brother of Hello World'); $pages[4] = array('id' => 4, 'parent' => 2, 'name' => 'Grand-child of Hello World'); $pages[6] = array('id' => 6, 'parent' => 4, 'name' => 'Great-grand-child of Hello World'); $children = array(); foreach($pages as $key => $page){ $parent = (int)$page['parent']; if(!isset($children[$parent])){ $children[$parent] = array(); $children[$parent][$key] = array('id' => $page['id'], 'name' => $page['name']); } } var_dump($children);
Output for git.master, git.master_jit, rfc.property-hooks
array(4) { [0]=> array(1) { [1]=> array(2) { ["id"]=> int(1) ["name"]=> string(11) "Hello World" } } [1]=> array(1) { [2]=> array(2) { ["id"]=> int(1) ["name"]=> string(20) "Child of Hello World" } } [2]=> array(1) { [4]=> array(2) { ["id"]=> int(4) ["name"]=> string(26) "Grand-child of Hello World" } } [4]=> array(1) { [6]=> array(2) { ["id"]=> int(6) ["name"]=> string(32) "Great-grand-child of Hello World" } } }

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