3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
$tree = array( 1 => array( 'parent' => 0 ), 2 => array( 'parent' => 1 ), 3 => array( 'parent' => 1 ), 4 => array( 'parent' => 2 ) ); $newtree = array(); foreach($tree as $leaf) { if (!isset($newtree[$leaf['parent']])) $newtree[$leaf['parent']]=array(); $newtree[$leaf['parent']][]=$leaf; } <?php>print_r($newtree); </?>
Output for 5.4.0 - 5.5.8
Parse error: syntax error, unexpected '<' in /in/tf6LH on line 11
Process exited with code 255.
Output for 4.3.0 - 5.3.29
$tree = array( 1 => array( 'parent' => 0 ), 2 => array( 'parent' => 1 ), 3 => array( 'parent' => 1 ), 4 => array( 'parent' => 2 ) ); $newtree = array(); foreach($tree as $leaf) { if (!isset($newtree[$leaf['parent']])) $newtree[$leaf['parent']]=array(); $newtree[$leaf['parent']][]=$leaf; } <?php>print_r($newtree); </?>