3v4l.org

run code in 300+ PHP versions simultaneously
<?php $menu = array( array(7,1,'Baer 1.1.1', 3, 0), array(9,4,'Esel 2.2.1', 3, 0), array(1,3,'Wurm 1.1', 2, 10), array(3,0,'Tiger 1', 1, 10), array(5,3,'Katze 1.2', 2, 11), array(8,3,'Schwein 1.3', 2, 12), array(2,6,'Vogel 2.1', 2, 30), array(4,6,'Hund 2.2', 2, 40), array(6,0,'Pferd 2', 1, 20), ); // Algorithmus hier /** * This Class represents a single folder Node * * @package wbsFramework * @subpackage * @author -=WBS=- * Wolfgang Blessen Software * www.blessen.de * @copyright private * @version 2.5 * @since 13.05.15 */ class FolderNode { /** * @var int */ private $ID; /** * @var string */ private $Name; /** * @var int */ private $Level; /** * @var array Array of {FolderNode} */ private $Children; /** * @var FolderNode | null */ private $Parent; /** * Create a new Node * * @param int $ID * @param string $Name */ public function __construct($ID,$Name) { #shout('new FolderNode '.$ID.': '.$Name); $this->ID = (int)$ID; $this->Name = $Name; $this->Children = array(); $this->Parent = null; } /** * @return int */ public function getID() { return $this->ID; } /** * @param int $ID */ public function setID($ID) { $this->ID = (int)$ID; } /** * @return string */ public function getName() { return $this->Name; } /** * @param string $Name */ public function setName($Name) { $this->Name = $Name; } /** * @return int */ public function getLevel() { return $this->Level; } /** * @param int $Level */ public function setLevel($Level) { $this->Level = (int)$Level; } /** * @return FolderNode[] Array of All Children */ public function getChildren() { return $this->Children; } /** * @return boolean Do we have children */ public function hasChildren() { return count($this->Children) ? true : false; } /** * @param FolderNode $Child */ public function addChild(FolderNode $Child) { $this->Children[] = $Child; } /** * @return FolderNode|null */ public function getParent() { return $this->Parent; } /** * @return boolean */ public function hasParent() { return ($this->Parent !== null); } /** * @param FolderNode|null $Parent */ public function setParent($Parent) { $this->Parent = $Parent; } } /** * @param FolderNode $FolderNode * @param array $FolderList * @param int $current_level * * @return bool */ function findChildren($FolderNode,$FolderList, $current_level){ $myID = $FolderNode->getID(); $found_child =false; foreach((array)$FolderList as $folder) { if($folder[1] == $myID){ //Setup a new Node $child_node = new FolderNode($folder[0],$folder[2]); $child_node->setLevel($current_level); $child_node->setParent($FolderNode); findChildren($child_node,$FolderList,$current_level+1); $FolderNode->addChild($child_node); //Find the Children $found_child = true; } } return $found_child; } $menu_by_id = []; foreach($menu as $item){ $menu_by_id[$item[0]] = $item; } // Set the Root Level $current_level = 0; $root_node = new FolderNode(0,'Root'); $root_node->setLevel($current_level); $root_node->setParent(null); findChildren($root_node,$menu,$current_level +1); $result = array(); foreach($root_node->getChildren() as $the_child){ $i =0; $result[] = $menu_by_id[$the_child->getID()]; if($the_child->hasChildren()){ foreach($the_child->getChildren() as $the_grand_child){ $result[] = $menu_by_id[$the_grand_child->getID()]; foreach($the_grand_child->getChildren() as $the_grand_grand_child){ $result[] = $menu_by_id[$the_grand_grand_child->getID()]; } } } } //var_dump($result); $target = array( array(3,0,'Tiger 1', 1, 10), array(1,3,'Wurm 1.1', 2, 10), array(7,1,'Baer 1.1.1', 3, 0), array(5,3,'Katze 1.2', 2, 11), array(8,3,'Schwein 1.3', 2, 12), array(6,0,'Pferd 2', 1, 20), array(2,6,'Vogel 2.1', 2, 30), array(4,6,'Hund 2.2', 2, 40), array(9,4,'Esel 2.2.1', 3, 0), ); var_dump($result == $target);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.120.0080.00824.18
8.4.110.0130.01118.96
8.4.100.0160.00518.82
8.4.90.0140.00420.54
8.4.80.0050.00518.86
8.4.70.0100.00717.95
8.4.60.0120.00918.71
8.4.50.0050.00318.61
8.4.40.0100.01017.22
8.4.30.0090.01217.57
8.4.20.0070.01118.05
8.4.10.0040.00417.94
8.3.250.0090.01018.92
8.3.240.0040.00517.28
8.3.230.0140.00616.91
8.3.220.0060.00419.01
8.3.210.0060.01016.84
8.3.200.0040.00516.66
8.3.190.0060.00217.53
8.3.180.0140.00717.35
8.3.170.0090.00919.27
8.3.160.0150.00316.90
8.3.150.0150.00317.04
8.3.140.0060.01318.32
8.3.130.0030.00618.23
8.3.120.0040.00418.87
8.3.110.0040.00420.94
8.3.100.0030.00624.06
8.3.90.0140.00426.77
8.3.80.0050.00518.43
8.3.70.0060.00918.55
8.3.60.0170.00318.32
8.3.50.0110.01121.04
8.3.40.0070.00718.79
8.3.30.0100.00319.27
8.3.20.0040.00420.26
8.3.10.0000.00823.66
8.3.00.0080.00019.20
8.2.290.0140.00620.55
8.2.280.0050.00418.79
8.2.270.0100.01018.95
8.2.260.0050.00316.95
8.2.250.0030.00616.56
8.2.240.0090.00018.91
8.2.230.0030.00622.58
8.2.220.0030.00637.54
8.2.210.0090.00926.77
8.2.200.0030.00616.75
8.2.190.0110.00416.75
8.2.180.0080.00816.75
8.2.170.0140.00719.04
8.2.160.0070.00722.96
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0000.00821.19
8.2.110.0130.01020.39
8.2.100.0040.00817.91
8.2.90.0080.00018.28
8.2.80.0040.00417.97
8.2.70.0030.00617.88
8.2.60.0030.00618.29
8.2.50.0030.00618.07
8.2.40.0050.00320.00
8.2.30.0060.00318.20
8.2.20.0000.00817.84
8.2.10.0040.00418.09
8.2.00.0000.00818.27
8.1.330.0130.00822.17
8.1.320.0130.00818.11
8.1.310.0040.01117.93
8.1.300.0030.00617.97
8.1.290.0030.00630.84
8.1.280.0140.00425.92
8.1.270.0180.00320.32
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0060.00322.59
8.1.230.0070.00421.09
8.1.220.0000.00817.78
8.1.210.0040.00418.98
8.1.200.0100.00017.48
8.1.190.0050.00317.38
8.1.180.0050.00318.10
8.1.170.0030.00718.69
8.1.160.0080.00022.16
8.1.150.0040.00419.04
8.1.140.0040.00417.55
8.1.130.0020.00517.79
8.1.120.0030.00317.46
8.1.110.0030.00617.45
8.1.100.0000.00717.55
8.1.90.0040.00417.56
8.1.80.0040.00417.61
8.1.70.0030.00317.46
8.1.60.0000.00917.57
8.1.50.0000.00817.52
8.1.40.0040.00417.54
8.1.30.0040.00417.66
8.1.20.0000.00817.64
8.1.10.0030.00517.57
8.1.00.0000.00817.57
8.0.300.0040.00420.05
8.0.290.0020.00516.88
8.0.280.0000.00818.65
8.0.270.0030.00317.35
8.0.260.0030.00317.40
8.0.250.0040.00416.99
8.0.240.0030.00317.14
8.0.230.0040.00417.09
8.0.220.0040.00417.03
8.0.210.0000.00717.07
8.0.200.0050.00317.13
8.0.190.0030.00517.02
8.0.180.0050.00217.00
8.0.170.0040.00417.08
8.0.160.0080.00017.12
8.0.150.0000.00716.89
8.0.140.0070.00017.08
8.0.130.0030.00313.46
8.0.120.0030.00616.95
8.0.110.0040.00417.08
8.0.100.0070.00016.93
8.0.90.0000.00717.06
8.0.80.0070.01416.98
8.0.70.0000.00717.17
8.0.60.0030.00617.17
8.0.50.0000.00816.95
8.0.30.0150.00917.18
8.0.20.0070.01117.40
8.0.10.0040.00417.21
8.0.00.0110.00616.81
7.4.330.0020.00215.03
7.4.320.0000.00616.50
7.4.300.0000.00716.61
7.4.290.0070.00016.63
7.4.280.0040.00416.60
7.4.270.0030.00316.63
7.4.260.0000.00716.63
7.4.250.0040.00416.56
7.4.240.0020.00516.60
7.4.230.0070.00016.62
7.4.220.0150.00316.74
7.4.210.0060.01216.65
7.4.200.0030.00316.62
7.4.160.0090.00916.53
7.4.150.0170.00017.40
7.4.140.0110.01117.86
7.4.130.0130.00616.49
7.4.120.0110.00816.59
7.4.110.0090.00916.79
7.4.100.0090.00916.65
7.4.90.0000.01916.55
7.4.80.0000.01819.39
7.4.70.0080.01016.59
7.4.60.0060.01616.59
7.4.50.0030.00316.50
7.4.40.0130.00316.50
7.4.30.0000.01816.62
7.4.00.0050.01215.10
7.3.330.0070.00013.42
7.3.320.0140.00013.45
7.3.310.0000.00716.55
7.3.300.0000.00716.45
7.3.290.0030.01316.43
7.3.280.0140.00616.47
7.3.270.0120.00617.40
7.3.260.0130.00316.55
7.3.250.0070.01016.54
7.3.240.0110.00816.47
7.3.230.0120.00816.68
7.3.210.0100.00816.64
7.3.200.0090.01516.57
7.3.190.0040.01216.43
7.3.180.0150.00316.58
7.3.170.0120.00616.72
7.3.160.0060.01216.63
7.3.120.0060.01215.08
7.3.110.0070.00914.63
7.3.100.0050.00814.68
7.3.90.0100.00514.80
7.3.80.0040.01015.03
7.3.70.0050.00714.97
7.3.60.0050.00914.93
7.3.50.0080.00514.60
7.3.40.0050.00514.75
7.3.30.0050.01014.88
7.3.20.0030.01216.60
7.3.10.0110.00116.64
7.3.00.0050.01016.79
7.2.330.0000.01916.53
7.2.320.0090.00816.80
7.2.310.0090.01616.44
7.2.300.0080.00816.54
7.2.290.0060.01216.91
7.2.250.0060.01315.34
7.2.240.0090.00915.26
7.2.230.0100.00515.13
7.2.220.0110.00515.17
7.2.210.0020.01114.83
7.2.200.0060.00715.15
7.2.190.0050.01114.99
7.2.180.0050.00814.94
7.2.170.0080.00814.93
7.2.160.0030.01515.03
7.2.150.0060.00917.12
7.2.140.0040.01216.91
7.2.130.0030.00716.83
7.2.120.0090.00616.67
7.2.110.0120.00616.90
7.2.100.0070.01016.89
7.2.90.0100.00316.60
7.2.80.0090.00616.95
7.2.70.0120.00616.95
7.2.60.0030.00717.06
7.2.50.0060.01216.93
7.2.40.0080.00816.85
7.2.30.0040.01416.70
7.2.20.0040.00817.02
7.2.10.0070.00717.02
7.2.00.0000.01216.87
7.1.330.0070.00615.67
7.1.320.0030.00815.74
7.1.310.0050.00815.74
7.1.300.0020.01415.69
7.1.290.0100.00315.73
7.1.280.0050.00815.71
7.1.270.0040.01215.84
7.1.260.0020.01515.74
7.1.250.0090.00615.84
7.1.200.0170.00615.37
7.1.70.0090.00017.29
7.1.60.0140.01019.50
7.1.50.0060.01617.00
7.1.00.0030.07722.48
7.0.200.0030.00716.85
7.0.60.0030.08720.07
7.0.50.0170.07717.92
7.0.40.0100.08320.26
7.0.30.0630.06020.30
7.0.20.0430.06720.33
7.0.10.0130.08320.07
7.0.00.0000.05320.20
5.6.280.0070.07020.87
5.6.210.0030.05020.55
5.6.200.0200.06718.21
5.6.190.0100.05020.61
5.6.180.3530.03720.42
5.6.170.0300.04320.58
5.6.160.0200.07020.39
5.6.150.0030.08018.21
5.6.140.0130.08018.19
5.6.130.0100.08318.22
5.6.120.0030.05721.05
5.6.110.0100.08721.03
5.6.100.0000.06321.05
5.6.90.0170.03321.05
5.6.80.0170.07720.58
5.5.350.0070.04720.43
5.5.340.0170.07018.02
5.5.330.0130.08320.38
5.5.320.0530.06320.24
5.5.310.0330.07720.51
5.5.300.0070.08017.99
5.5.290.0070.08718.04
5.5.280.0170.07720.90
5.5.270.0100.08020.96
5.5.260.0030.09320.69
5.5.250.0100.06020.73
5.5.240.0030.06020.23
5.4.450.0070.03319.59
5.4.440.0070.03319.45
5.4.430.0700.02719.27
5.4.420.0130.05319.32
5.4.410.0170.05018.81
5.4.400.0130.05018.88
5.4.390.0130.05018.78
5.4.380.0030.06018.79
5.4.370.0130.05018.77
5.4.360.0070.06018.81
5.4.350.0100.06318.75
5.4.340.0000.06318.62
5.4.320.0070.06018.80
5.4.310.0100.05318.79
5.4.300.0100.05018.81
5.4.290.0030.06718.62
5.4.280.0030.06018.55
5.4.270.0070.06018.75
5.4.260.0230.04018.80
5.4.250.0130.05318.54
5.4.240.0170.05018.79
5.4.230.0100.06318.82
5.4.220.0030.06018.61
5.4.210.0070.05718.79
5.4.200.0100.06016.68
5.4.190.0130.07318.77
5.4.180.0130.05318.73
5.4.170.0100.05718.76
5.4.160.0170.04718.79
5.4.150.0230.04018.56
5.4.140.0100.05016.29
5.4.130.0070.06316.34
5.4.120.0170.04316.33
5.4.110.0170.04316.34
5.4.100.0100.06716.29
5.4.90.0170.04716.43
5.4.80.0130.06316.36
5.4.70.0130.05016.16
5.4.60.0100.05016.47
5.4.50.0300.04016.26
5.4.40.0200.04716.24
5.4.30.0070.05016.25
5.4.20.0030.06016.27
5.4.10.0130.05316.29
5.4.00.0130.05015.92
5.3.290.0030.06014.88
5.3.280.0130.05014.74
5.3.270.0070.06014.81
5.3.260.0130.05014.66
5.3.250.0030.06014.85
5.3.240.0130.05714.69
5.3.230.0100.05014.73
5.3.220.0200.04714.73
5.3.210.0030.06014.64
5.3.200.0130.05014.61
5.3.190.0130.04714.65
5.3.180.0170.05714.81
5.3.170.0070.05314.59
5.3.160.0130.05014.63
5.3.150.0100.05714.64
5.3.140.0130.04714.70
5.3.130.0170.04714.74
5.3.120.0070.05714.70
5.3.110.0100.05314.61
5.3.100.0170.05314.11
5.3.90.0070.05314.04
5.3.80.0030.05714.02
5.3.70.0070.05314.10
5.3.60.0100.05014.16
5.3.50.0130.05013.96
5.3.40.0030.06014.07
5.3.30.0000.06014.00
5.3.20.0070.05313.89
5.3.10.0170.04313.90
5.3.00.0130.04713.72
5.2.170.0030.05311.39
5.2.160.0030.04311.29
5.2.150.0030.04711.17
5.2.140.0070.04311.28
5.2.130.0170.03311.28
5.2.120.0070.06011.16
5.2.110.0100.04311.16
5.2.100.0000.05011.23
5.2.90.0070.04011.34
5.2.80.0130.03711.13
5.2.70.0170.04711.17
5.2.60.0070.04711.18
5.2.50.0170.03311.03
5.2.40.0100.04311.05
5.2.30.0130.04011.03
5.2.20.0070.04011.01
5.2.10.0070.04310.94
5.2.00.0100.04010.79
5.1.60.0130.02710.06
5.1.50.0030.03710.23
5.1.40.0030.03710.08
5.1.30.0130.03010.36
5.1.20.0070.03710.48
5.1.10.0070.03310.14
5.1.00.0070.04010.29
5.0.50.0070.0308.58
5.0.40.0000.0308.66
5.0.30.0000.0508.29
5.0.20.0000.0338.34
5.0.10.0030.0308.29
5.0.00.0070.0408.39
4.4.90.0030.0236.82
4.4.80.0070.0206.82
4.4.70.0070.0206.82
4.4.60.0070.0206.82
4.4.50.0000.0236.82
4.4.40.0070.0336.82
4.4.30.0030.0206.82
4.4.20.0030.0236.82
4.4.10.0030.0236.82
4.4.00.0030.0336.82
4.3.110.0000.0306.82
4.3.100.0030.0276.82
4.3.90.0000.0236.82
4.3.80.0030.0336.82
4.3.70.0000.0236.82
4.3.60.0030.0206.82
4.3.50.0030.0336.82
4.3.40.0030.0336.82
4.3.30.0030.0206.82
4.3.20.0030.0236.82
4.3.10.0000.0236.82
4.3.00.0330.01015.75

preferences:
78.14 ms | 403 KiB | 5 Q