3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a= array ( 1 => 0, 2 => 1, 3 => 2, 4 => 3, 5 => 1, 6 => 0 ); class node { var $children; public function __construct(){ $this->children = array(); } } $tree = array(); foreach ($a as $q => $p){ if(!isset($tree[$p])) $tree[$p] = new node; if(!isset($tree[$q])) $tree[$q] = new node; $mark[$p]=FALSE; $mark[$q]=FALSE; array_push($tree[$p]->children,$q); } function dfs(&$ans,$node){ global $tree, $mark; $mark[$node] = TRUE; $ans = array(); foreach($tree[$node]->children as $child) if(!$mark[$child]){ $ans[$child]=$child; dfs($ans[$child],$child); } } $parent=1; dfs($ans,$parent); echo($ans[0]); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined array key 0 in /in/7rNhW on line 47

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:
33.82 ms | 401 KiB | 8 Q