3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CategoryTree { protected $roots = []; public function addCategory($category, $parent) { if ($this->categoryExists($this->roots, $category)) { throw new InvalidArgumentException("Category: '$category' already exists."); } if ($parent === null) { $this->roots[$category] = []; return; } $node = &$this->findNode($parent, $this->roots); if(!isset($node)) { throw new InvalidArgumentException("Parent node: '$parent' not found."); } $node[$category] = []; } public function getChildren($parent) { $node = $this->findNode($parent, $this->roots); if(!isset($node)) { throw new InvalidArgumentException("Parent node: '$parent' not found."); } return array_keys($node); } protected function &findNode($node, &$root) { if (in_array($node, array_keys($root))) { return $root[$node]; } foreach ($root as $n) { return $this->findNode($node, $n); } } protected function categoryExists($nodes, $category) { $exists = false; foreach($nodes as $key => $node) { if ($key === $category) { return true; } $exists = $this->categoryExists($node, $category); } return $exists; } } // For testing purposes (do not submit uncommented): $c = new CategoryTree; $c->addCategory('A', null); $c->addCategory('B', 'A'); $c->addCategory('C', 'A'); echo implode(',', $c->getChildren('A'));

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.3.60.0090.00616.88
8.3.50.0080.01021.99
8.3.40.0000.01418.79
8.3.30.0060.01218.61
8.3.20.0070.00020.16
8.3.10.0050.00323.71
8.3.00.0040.00420.04
8.2.180.0110.00418.54
8.2.170.0110.00722.96
8.2.160.0030.01020.53
8.2.150.0000.00824.18
8.2.140.0050.00324.66
8.2.130.0030.00521.11
8.2.120.0060.00326.35
8.2.110.0060.00320.53
8.2.100.0080.00318.03
8.2.90.0040.00419.24
8.2.80.0040.00417.97
8.2.70.0000.00817.75
8.2.60.0100.00018.05
8.2.50.0090.00018.07
8.2.40.0080.00021.11
8.2.30.0030.00620.61
8.2.20.0050.00317.84
8.2.10.0040.00418.16
8.2.00.0060.00318.07
8.1.280.0150.00025.92
8.1.270.0050.00320.73
8.1.260.0030.00528.09
8.1.250.0000.00828.09
8.1.240.0030.00622.23
8.1.230.0040.00819.66
8.1.220.0080.00017.74
8.1.210.0050.00318.77
8.1.200.0100.00017.25
8.1.190.0060.00317.23
8.1.180.0000.00818.10
8.1.170.0030.00618.66
8.1.160.0000.00720.71
8.1.150.0040.00419.01
8.1.140.0080.00019.62
8.1.130.0040.00417.65
8.1.120.0040.00417.52
8.1.110.0000.00817.43
8.1.100.0050.00317.43
8.1.90.0040.00417.47
8.1.80.0000.00717.55
8.1.70.0030.00317.47
8.1.60.0040.00417.51
8.1.50.0090.00017.56
8.1.40.0050.00317.54
8.1.30.0000.00917.57
8.1.20.0040.00417.54
8.1.10.0000.00717.66
8.1.00.0030.00517.44
8.0.300.0040.00418.77
8.0.290.0020.00516.88
8.0.280.0030.00318.40
8.0.270.0030.00517.18
8.0.260.0030.00317.28
8.0.250.0050.00216.90
8.0.240.0050.00317.02
8.0.230.0030.00316.86
8.0.220.0000.00716.90
8.0.210.0000.00816.84
8.0.200.0030.00516.95
8.0.190.0070.00017.02
8.0.180.0000.00816.99
8.0.170.0060.00316.83
8.0.160.0000.00717.04
8.0.150.0040.00416.86
8.0.140.0040.00716.87
8.0.130.0030.00313.40
8.0.120.0000.00816.87
8.0.110.0000.00716.84
8.0.100.0050.00216.96
8.0.90.0040.00416.80
8.0.80.0060.01016.93
8.0.70.0000.00716.87
8.0.60.0070.00017.00
8.0.50.0080.00016.99
8.0.30.0080.01017.13
8.0.20.0130.00717.41
8.0.10.0000.00816.93
8.0.00.0070.01316.63
7.4.330.0050.00016.84
7.4.320.0040.00416.63
7.4.300.0000.00716.53
7.4.290.0000.00716.68
7.4.280.0000.00916.59
7.4.270.0080.00016.65
7.4.260.0000.01216.55
7.4.250.0080.00016.63
7.4.240.0070.00116.67
7.4.230.0030.00316.66
7.4.220.0090.00916.74
7.4.210.0050.01116.58
7.4.200.0000.00716.62
7.4.160.0070.01016.68
7.4.150.0090.00917.40
7.4.140.0090.01417.86
7.4.130.0130.00516.54
7.4.120.0070.01216.60
7.4.110.0130.01316.39
7.4.100.0070.01016.53
7.4.90.0100.00716.52
7.4.80.0100.01019.39
7.4.70.0050.01116.62
7.4.60.0170.00416.57
7.4.50.0060.01016.40
7.4.40.0140.00316.50
7.4.30.0130.00316.28
7.4.10.0090.00915.09
7.4.00.0060.01014.84
7.3.330.0030.00313.23
7.3.320.0050.00013.36
7.3.310.0000.00716.45
7.3.300.0000.00716.38
7.3.290.0000.00716.36
7.3.280.0110.00616.41
7.3.270.0130.00517.40
7.3.260.0090.00916.50
7.3.250.0090.00816.43
7.3.240.0090.00816.50
7.3.230.0100.01416.51
7.3.210.0070.01016.40
7.3.200.0080.00816.48
7.3.190.0080.00816.48
7.3.180.0100.00616.52
7.3.170.0060.01516.46
7.3.160.0060.01016.59
7.3.130.0110.00714.97
7.3.120.0080.01014.88
7.3.110.0040.01415.14
7.3.100.0060.00914.76
7.3.90.0050.01014.89
7.3.80.0090.00614.91
7.3.70.0060.00715.00
7.3.60.0070.01115.01
7.3.50.0030.01214.93
7.3.40.0100.00714.96
7.3.30.0070.01014.90
7.3.20.0060.00616.83
7.3.10.0090.00616.53
7.3.00.0060.00816.74
7.2.330.0080.01216.70
7.2.320.0130.00616.78
7.2.310.0000.01616.83
7.2.300.0100.00716.70
7.2.290.0140.00416.81
7.2.260.0070.01115.11
7.2.250.0050.01415.08
7.2.240.0050.01315.09
7.2.230.0060.00615.06
7.2.220.0070.00615.21
7.2.210.0050.00714.99
7.2.200.0030.00614.88
7.2.190.0070.00915.13
7.2.180.0070.00914.89
7.2.170.0030.00915.13
7.2.160.0040.01115.20
7.2.150.0060.01317.11
7.2.140.0030.01616.96
7.2.130.0030.01216.95
7.2.120.0080.00817.00
7.2.110.0080.00316.88
7.2.100.0020.01216.91
7.2.90.0050.00817.08
7.2.80.0080.00517.04
7.2.70.0050.00717.00
7.2.60.0040.01116.83
7.2.50.0070.00816.90
7.2.40.0070.00716.87
7.2.30.0050.00716.86
7.2.20.0080.00616.74
7.2.10.0110.00216.97
7.2.00.0120.00517.77
7.1.330.0050.00915.93
7.1.320.0060.01115.81
7.1.310.0060.00915.66
7.1.300.0040.01115.74
7.1.290.0040.01115.80
7.1.280.0050.00715.80
7.1.270.0080.00915.71
7.1.260.0050.00815.83
7.1.250.0060.00515.71
7.1.240.0040.00915.95
7.1.230.0030.01015.76
7.1.220.0080.00515.76
7.1.210.0090.00315.82
7.1.200.0030.01015.67
7.1.190.0050.00315.83
7.1.180.0070.00815.78
7.1.170.0080.00515.97
7.1.160.0080.00515.59
7.1.150.0070.00715.58
7.1.140.0030.01215.75
7.1.130.0090.00515.66
7.1.120.0030.01015.89
7.1.110.0050.00515.91
7.1.100.0050.00716.70
7.1.90.0050.01015.73
7.1.80.0040.00615.75
7.1.70.0060.00516.19
7.1.60.0050.01216.81
7.1.50.0050.00916.12
7.1.40.0060.00415.68
7.1.30.0120.00715.78
7.1.20.0040.00615.75
7.1.10.0070.00715.70
7.1.00.0070.03018.07
7.0.330.0080.00615.34
7.0.320.0060.00315.40
7.0.310.0060.00915.40
7.0.300.0000.01215.29
7.0.290.0050.00515.36
7.0.280.0060.00815.26
7.0.270.0070.00615.32
7.0.260.0050.00915.37
7.0.250.0020.01115.53
7.0.240.0060.00615.39
7.0.230.0070.00715.48
7.0.220.0050.00515.41
7.0.210.0040.00715.34
7.0.200.0030.00615.75
7.0.190.0050.00815.33
7.0.180.0070.00715.30
7.0.170.0070.00715.28
7.0.160.0080.00415.43
7.0.150.0060.01015.35
7.0.140.0110.00515.44
7.0.130.0020.01215.42
7.0.120.0110.00515.59
7.0.110.0040.00715.26
7.0.100.0050.00515.25
7.0.90.0060.00615.48
7.0.80.0080.00815.24
7.0.70.0060.00915.48
7.0.60.0070.01716.95
7.0.50.0070.02216.21
7.0.40.0030.02315.70
7.0.30.0090.02015.87
7.0.20.0110.03015.69
7.0.10.0060.02015.76
7.0.00.0050.02315.68
5.6.400.0090.00614.71
5.6.390.0000.01514.24
5.6.380.0050.00514.47
5.6.370.0040.00914.42
5.6.360.0070.00314.55
5.6.350.0050.00714.36
5.6.340.0070.00514.55
5.6.330.0070.00514.35
5.6.320.0060.00614.75
5.6.310.0080.00314.35
5.6.300.0080.00814.57
5.6.290.0090.00514.30
5.6.280.0040.01616.43
5.6.270.0070.00714.41
5.6.260.0090.00614.47
5.6.250.0080.00314.50
5.6.240.0000.01214.43
5.6.230.0070.00314.40
5.6.220.0100.00514.31
5.6.210.0080.01616.45
5.6.200.0050.03315.82
5.6.190.0050.02016.43
5.6.180.0130.02916.57
5.6.170.0100.02516.49
5.6.160.0080.03116.42
5.6.150.0120.02815.69
5.6.140.0080.02515.76
5.6.130.0100.01915.66
5.6.120.0110.02716.63
5.6.110.0120.02416.57
5.6.100.0070.03116.80
5.6.90.0080.03116.75
5.6.80.0100.02516.39
5.6.70.0080.00714.41
5.6.60.0060.00614.68
5.6.50.0040.00414.39
5.6.40.0050.00914.27
5.6.30.0080.00514.30
5.6.20.0030.00914.26
5.6.10.0010.00914.26
5.6.00.0090.00514.13
5.5.380.0090.00412.96
5.5.370.0050.00712.96
5.5.360.0020.01012.86
5.5.350.0940.01415.46
5.5.340.0030.03014.61
5.5.330.0020.03515.40
5.5.320.0120.01815.26
5.5.310.0070.02015.32
5.5.300.0070.03014.65
5.5.290.0050.03014.54
5.5.280.0040.03315.43
5.5.270.0070.02615.45
5.5.260.0090.02415.47
5.5.250.0060.03415.35
5.5.240.0080.01515.12
5.5.230.0060.00412.75
5.5.220.0030.00512.63
5.5.210.0030.00812.61
5.5.200.0040.00612.57
5.5.190.0060.00512.82
5.5.180.0060.00612.58
5.5.170.0050.00512.83
5.5.160.0090.00412.75
5.5.150.0070.00612.78
5.5.140.0050.00812.95
5.5.130.0070.00612.79
5.5.120.0070.00412.59
5.5.110.0060.00612.88
5.5.100.0030.00812.98
5.5.90.0080.00312.86
5.5.80.0020.01012.78
5.5.70.0020.00912.53
5.5.60.0030.00812.66
5.5.50.0040.00712.88
5.5.40.0050.00612.79
5.5.30.0060.00612.79
5.5.20.0050.00512.82
5.5.10.0050.00612.86
5.5.00.0060.00412.63

preferences:
33.09 ms | 401 KiB | 5 Q