3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a=array(array(207306,'Bob',''), array (199730,'Sam',199714), array(199728,'Simon',207306), array(199714,'John',207306), array(199716,'Tom',199718), array(199718,'Phillip',207306), array(199720,'James',207306)); # map the children by parent $parents = ['' => []]; foreach ($a as $val) { $parents[$val[2]][] = $val; } # start with those with no parent $sorted = $parents['']; # add the children the current nodes are parent of until the array is empty # a bit slower loop which works in all versions for ($val = reset($sorted); $val; $val = next($sorted)) { if (isset($parents[$val[0]])) { foreach ($parents[$val[0]] as $next) { $sorted[] = $next; } } } var_dump($sorted);
Output for git.master, git.master_jit, rfc.property-hooks
array(7) { [0]=> array(3) { [0]=> int(207306) [1]=> string(3) "Bob" [2]=> string(0) "" } [1]=> array(3) { [0]=> int(199728) [1]=> string(5) "Simon" [2]=> int(207306) } [2]=> array(3) { [0]=> int(199714) [1]=> string(4) "John" [2]=> int(207306) } [3]=> array(3) { [0]=> int(199718) [1]=> string(7) "Phillip" [2]=> int(207306) } [4]=> array(3) { [0]=> int(199720) [1]=> string(5) "James" [2]=> int(207306) } [5]=> array(3) { [0]=> int(199730) [1]=> string(3) "Sam" [2]=> int(199714) } [6]=> array(3) { [0]=> int(199716) [1]=> string(3) "Tom" [2]=> int(199718) } }

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:
58.26 ms | 403 KiB | 8 Q