3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Sqltree { private $FlatTable, $paths; public function __construct($FlatTable) { $this->FlatTable = $FlatTable; } public function generateTable($tree) { $this->paths = array(); $this->path_recursion($tree, array()); print_r($this->paths); } private function path_recursion($tree, $parents) { //Path erzeugen $this->paths[] = array($tree, $tree, 0); foreach($parents as $parent) { $this->paths[] = array($parent['id'], $tree['id'], $parents['path_length']); $parents['path_length']++; } if(is_array($tree['children'])) { $parents = array('id' => $tree['id'], 'path_length' => 1); foreach($tree['children'] as $child) { $this->path_recursion($child, $parents); } } } public static function CreateTable($FlatTable) { $sql = "CREATE TABLE ClosureTable ( ancestor_id INT NOT NULL REFERENCES $FlatTable(id), descendant_id INT NOT NULL REFERENCES $FlatTable(id), path_length INT, PRIMARY KEY (ancestor_id, descendant_id) );"; sql::create($sql); } } $tree = array('id' => 1, 'children' => array(array('id' => 2, 'children' => array('id' => 4, 'children' => false)), array('id' => 3, 'children' => false))); print_r($tree); $sqltree = new SqlTree('asd'); $sqltree->generateTable($tree); ?>
Output for git.master, git.master_jit
Array ( [id] => 1 [children] => Array ( [0] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [1] => Array ( [id] => 3 [children] => ) ) ) Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Warning: Trying to access array offset on value of type int in /in/Os26C on line 19 Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Warning: Trying to access array offset on value of type bool in /in/Os26C on line 16 Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Warning: Trying to access array offset on value of type bool in /in/Os26C on line 16 Warning: Trying to access array offset on value of type bool in /in/Os26C on line 19 Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Warning: Trying to access array offset on value of type int in /in/Os26C on line 16 Array ( [0] => Array ( [0] => Array ( [id] => 1 [children] => Array ( [0] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [1] => Array ( [id] => 3 [children] => ) ) ) [1] => Array ( [id] => 1 [children] => Array ( [0] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [1] => Array ( [id] => 3 [children] => ) ) ) [2] => 0 ) [1] => Array ( [0] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [1] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [2] => 0 ) [2] => Array ( [0] => [1] => 2 [2] => 1 ) [3] => Array ( [0] => [1] => 2 [2] => 2 ) [4] => Array ( [0] => 4 [1] => 4 [2] => 0 ) [5] => Array ( [0] => [1] => [2] => 1 ) [6] => Array ( [0] => [1] => [2] => 2 ) [7] => Array ( [0] => [1] => [2] => 0 ) [8] => Array ( [0] => [1] => [2] => 1 ) [9] => Array ( [0] => [1] => [2] => 2 ) [10] => Array ( [0] => Array ( [id] => 3 [children] => ) [1] => Array ( [id] => 3 [children] => ) [2] => 0 ) [11] => Array ( [0] => [1] => 3 [2] => 1 ) [12] => Array ( [0] => [1] => 3 [2] => 2 ) )
Output for rfc.property-hooks
Array ( [id] => 1 [children] => Array ( [0] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [1] => Array ( [id] => 3 [children] => ) ) ) Warning: Trying to access array offset on int in /in/Os26C on line 16 Warning: Trying to access array offset on int in /in/Os26C on line 16 Warning: Trying to access array offset on int in /in/Os26C on line 16 Warning: Trying to access array offset on int in /in/Os26C on line 16 Warning: Trying to access array offset on int in /in/Os26C on line 16 Warning: Trying to access array offset on int in /in/Os26C on line 16 Warning: Trying to access array offset on int in /in/Os26C on line 19 Warning: Trying to access array offset on int in /in/Os26C on line 16 Warning: Trying to access array offset on false in /in/Os26C on line 16 Warning: Trying to access array offset on int in /in/Os26C on line 16 Warning: Trying to access array offset on false in /in/Os26C on line 16 Warning: Trying to access array offset on false in /in/Os26C on line 19 Warning: Trying to access array offset on int in /in/Os26C on line 16 Warning: Trying to access array offset on int in /in/Os26C on line 16 Array ( [0] => Array ( [0] => Array ( [id] => 1 [children] => Array ( [0] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [1] => Array ( [id] => 3 [children] => ) ) ) [1] => Array ( [id] => 1 [children] => Array ( [0] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [1] => Array ( [id] => 3 [children] => ) ) ) [2] => 0 ) [1] => Array ( [0] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [1] => Array ( [id] => 2 [children] => Array ( [id] => 4 [children] => ) ) [2] => 0 ) [2] => Array ( [0] => [1] => 2 [2] => 1 ) [3] => Array ( [0] => [1] => 2 [2] => 2 ) [4] => Array ( [0] => 4 [1] => 4 [2] => 0 ) [5] => Array ( [0] => [1] => [2] => 1 ) [6] => Array ( [0] => [1] => [2] => 2 ) [7] => Array ( [0] => [1] => [2] => 0 ) [8] => Array ( [0] => [1] => [2] => 1 ) [9] => Array ( [0] => [1] => [2] => 2 ) [10] => Array ( [0] => Array ( [id] => 3 [children] => ) [1] => Array ( [id] => 3 [children] => ) [2] => 0 ) [11] => Array ( [0] => [1] => 3 [2] => 1 ) [12] => Array ( [0] => [1] => 3 [2] => 2 ) )

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:
44.67 ms | 413 KiB | 8 Q