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 || in_array($category, $this->getChildren($key))) { 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('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.0110.00416.75
8.3.50.0130.00622.04
8.3.40.0100.01018.98
8.3.30.0090.00918.72
8.3.20.0080.00020.30
8.3.10.0040.00423.61
8.3.00.0080.00019.85
8.2.180.0060.00918.29
8.2.170.0070.00722.96
8.2.160.0070.00720.52
8.2.150.0080.00024.18
8.2.140.0060.00324.66
8.2.130.0060.00319.45
8.2.120.0000.00826.35
8.2.110.0060.00320.49
8.2.100.0040.00817.93
8.2.90.0000.00819.22
8.2.80.0060.00317.97
8.2.70.0080.00017.75
8.2.60.0050.00318.05
8.2.50.0000.00818.07
8.2.40.0050.00321.18
8.2.30.0000.00820.78
8.2.20.0040.00417.85
8.2.10.0000.00718.23
8.2.00.0040.00418.22
8.1.280.0090.00625.92
8.1.270.0030.00620.64
8.1.260.0040.00428.09
8.1.250.0030.00528.09
8.1.240.0090.00023.80
8.1.230.0090.00317.61
8.1.220.0050.00317.78
8.1.210.0040.00418.77
8.1.200.0040.00417.23
8.1.190.0080.00017.23
8.1.180.0030.00618.10
8.1.170.0050.00318.50
8.1.160.0050.00220.70
8.1.150.0000.00818.98
8.1.140.0000.00819.55
8.1.130.0040.00417.73
8.1.120.0050.00217.50
8.1.110.0080.00017.57
8.1.100.0000.00817.39
8.1.90.0080.00417.39
8.1.80.0000.00817.46
8.1.70.0070.00017.35
8.1.60.0000.00817.65
8.1.50.0000.00817.63
8.1.40.0030.00617.52
8.1.30.0000.00817.60
8.1.20.0080.00017.65
8.1.10.0070.00017.48
8.1.00.0080.00017.53
8.0.300.0040.00418.77
8.0.290.0000.00716.88
8.0.280.0000.00818.40
8.0.270.0030.00517.34
8.0.260.0000.00617.36
8.0.250.0000.00717.06
8.0.240.0070.00017.13
8.0.230.0070.00017.05
8.0.220.0040.00417.04
8.0.210.0050.00317.06
8.0.200.0000.00617.03
8.0.190.0030.00517.05
8.0.180.0030.00617.04
8.0.170.0050.00217.00
8.0.160.0030.00316.88
8.0.150.0040.00417.04
8.0.140.0060.00316.85
8.0.130.0050.00013.43
8.0.120.0080.00016.84
8.0.110.0050.00317.00
8.0.100.0050.00316.79
8.0.90.0040.00416.88
8.0.80.0100.00617.06
8.0.70.0070.00016.87
8.0.60.0000.00816.97
8.0.50.0000.00717.05
8.0.30.0100.01017.25
8.0.20.0080.01117.41
8.0.10.0020.00517.23
8.0.00.0050.01216.86
7.4.330.0000.00516.67
7.4.320.0030.00316.51
7.4.300.0040.00416.66
7.4.290.0030.00316.53
7.4.280.0060.00316.63
7.4.270.0030.00316.64
7.4.260.0030.00316.50
7.4.250.0000.00816.52
7.4.240.0040.00416.57
7.4.230.0070.00016.54
7.4.220.0090.00616.53
7.4.210.0090.00616.67
7.4.200.0040.00416.62
7.4.160.0070.01016.70
7.4.150.0190.00017.40
7.4.140.0200.00317.86
7.4.130.0120.00516.65
7.4.120.0080.01416.69
7.4.110.0100.01316.59
7.4.100.0170.00716.62
7.4.90.0240.03416.56
7.4.80.0060.01519.39
7.4.70.0030.01416.43
7.4.60.0130.00316.61
7.4.50.0060.01016.50
7.4.40.0030.01516.67
7.4.30.0070.01016.70
7.4.10.0090.00914.93
7.4.00.0050.01215.10
7.3.330.0030.00313.55
7.3.320.0050.00013.34
7.3.310.0030.00516.49
7.3.300.0040.00416.48
7.3.290.0000.00716.43
7.3.280.0100.00716.50
7.3.270.0110.00817.40
7.3.260.0160.00316.73
7.3.250.0070.01116.43
7.3.240.0080.01016.39
7.3.230.0110.00616.51
7.3.210.0060.01216.50
7.3.200.0060.01016.51
7.3.190.0100.00616.46
7.3.180.0130.00316.43
7.3.170.0100.00716.65
7.3.160.0040.01216.71
7.3.130.0060.01214.82
7.3.120.0070.00714.93
7.3.110.0070.01015.01
7.3.100.0060.00914.92
7.3.90.0070.01014.79
7.3.80.0020.00915.02
7.3.70.0020.01215.01
7.3.60.0030.01114.78
7.3.50.0080.00314.97
7.3.40.0090.00314.91
7.3.30.0070.00814.80
7.3.20.0040.00916.70
7.3.10.0080.00716.58
7.3.00.0070.00516.46
7.2.330.0120.01216.84
7.2.320.0140.01016.57
7.2.310.0100.01316.68
7.2.300.0070.01016.89
7.2.290.0090.00916.64
7.2.260.0030.01415.05
7.2.250.0120.00515.08
7.2.240.0080.00715.24
7.2.230.0080.00915.17
7.2.220.0060.00915.10
7.2.210.0050.00815.05
7.2.200.0020.01115.11
7.2.190.0100.00315.08
7.2.180.0050.00914.97
7.2.170.0090.00614.98
7.2.160.0030.00614.88
7.2.150.0100.00716.69
7.2.140.0030.01016.82
7.2.130.0080.00716.59
7.2.120.0070.01016.88
7.2.110.0080.00716.88
7.2.100.0080.00516.62
7.2.90.0020.01016.69
7.2.80.0070.00816.87
7.2.70.0050.00916.67
7.2.60.0080.00616.86
7.2.50.0100.00316.93
7.2.40.0090.00716.68
7.2.30.0060.01016.73
7.2.20.0120.00616.69
7.2.10.0050.01216.68
7.2.00.0090.00817.69
7.1.330.0080.00315.81
7.1.320.0050.01015.88
7.1.310.0060.00715.77
7.1.300.0060.00515.76
7.1.290.0040.00515.55
7.1.280.0050.00615.78
7.1.270.0060.00615.90
7.1.260.0050.00715.74
7.1.250.0100.00415.80
7.1.240.0030.01016.02
7.1.230.0000.00915.82
7.1.220.0030.00915.86
7.1.210.0040.00715.84
7.1.200.0070.00715.68
7.1.190.0030.00616.02
7.1.180.0030.01015.97
7.1.170.0030.01315.79
7.1.160.0030.01415.96
7.1.150.0030.01215.96
7.1.140.0060.00915.68
7.1.130.0090.00615.96
7.1.120.0000.01315.79
7.1.110.0070.00715.86
7.1.100.0080.00416.02
7.1.90.0040.00815.71
7.1.80.0000.01616.00
7.1.70.0070.00716.54
7.1.60.0020.01016.56
7.1.50.0070.00516.38
7.1.40.0000.00915.71
7.1.30.0000.00815.84
7.1.20.0070.00715.71
7.1.10.0030.00815.80
7.1.00.0070.04219.10
7.0.330.0030.01015.53
7.0.320.0040.00815.46
7.0.310.0030.01015.27
7.0.300.0060.01015.48
7.0.290.0000.01215.29
7.0.280.0080.00515.45
7.0.270.0100.00015.21
7.0.260.0070.00715.10
7.0.250.0000.01515.29
7.0.240.0030.00615.48
7.0.230.0100.00315.47
7.0.220.0000.01315.54
7.0.210.0000.01615.40
7.0.200.0040.01115.90
7.0.190.0060.00615.25
7.0.180.0030.01015.50
7.0.170.0000.01215.46
7.0.160.0030.00815.48
7.0.150.0050.00315.32
7.0.140.0080.00815.22
7.0.130.0000.01215.34
7.0.120.0000.01115.25
7.0.110.0030.00615.45
7.0.100.0000.01315.61
7.0.90.0080.00015.46
7.0.80.0060.00615.41
7.0.70.0030.00615.42
7.0.60.0030.04817.75
7.0.50.0070.03316.61
7.0.40.0120.04216.75
7.0.30.0150.02816.92
7.0.20.0170.03816.79
7.0.10.0070.03516.87
7.0.00.0000.04916.82
5.6.400.0040.00714.14
5.6.390.0070.00714.48
5.6.380.0100.00314.50
5.6.370.0080.00814.84
5.6.360.0060.00914.35
5.6.350.0060.00614.25
5.6.340.0040.01214.76
5.6.330.0060.00614.26
5.6.320.0000.01614.49
5.6.310.0070.01014.77
5.6.300.0060.00314.26
5.6.290.0040.01114.68
5.6.280.0020.02217.68
5.6.270.0090.00614.56
5.6.260.0100.00314.43
5.6.250.0000.01214.55
5.6.240.0000.01414.58
5.6.230.0060.00314.82
5.6.220.0110.00314.43
5.6.210.0070.02517.55
5.6.200.0070.04716.44
5.6.190.0080.03017.49
5.6.180.0180.04317.33
5.6.170.0160.03817.55
5.6.160.0060.04617.46
5.6.150.0050.04216.29
5.6.140.0050.03816.46
5.6.130.0070.02716.45
5.6.120.0050.02817.65
5.6.110.0080.04417.78
5.6.100.0020.03017.59
5.6.90.0080.02517.71
5.6.80.0060.02817.34
5.6.70.0070.00714.29
5.6.60.0100.00314.46
5.6.50.0060.00614.52
5.6.40.0000.01414.20
5.6.30.0110.00414.52
5.6.20.0080.00814.38
5.6.10.0120.00314.23
5.6.00.0050.00514.36
5.5.380.0070.00714.62
5.5.370.0060.00914.52
5.5.360.0040.01114.23
5.5.350.2000.02417.28
5.5.340.0080.02816.30
5.5.330.0020.04917.30
5.5.320.0120.04517.51
5.5.310.0150.02017.22
5.5.300.0050.04616.04
5.5.290.0090.04116.41
5.5.280.0070.04017.57
5.5.270.0080.02017.46
5.5.260.0070.04517.46
5.5.250.0070.02417.48
5.5.240.0060.02617.33
5.5.230.0000.00914.40
5.5.220.0060.00914.31
5.5.210.0080.00614.39
5.5.200.0120.00414.66
5.5.190.0140.00014.51
5.5.180.0100.00714.63
5.5.170.0000.01114.41
5.5.160.0030.00614.51
5.5.150.0000.01514.32
5.5.140.0090.00614.63
5.5.130.0090.00914.25
5.5.120.0090.00914.25
5.5.110.0040.01414.43
5.5.100.0030.01214.26
5.5.90.0080.00814.22
5.5.80.0060.00614.30
5.5.70.0000.01514.54
5.5.60.0120.00314.54
5.5.50.0030.01014.54
5.5.40.0000.01314.38
5.5.30.0060.00914.47
5.5.20.0070.00714.41
5.5.10.0030.01214.43
5.5.00.0000.01414.38

preferences:
64.04 ms | 401 KiB | 5 Q