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 (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('B', '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.0040.01116.63
8.3.50.0050.01322.05
8.3.40.0100.01018.77
8.3.30.0070.00718.65
8.3.20.0040.00420.25
8.3.10.0040.00423.52
8.3.00.0040.00419.84
8.2.180.0090.01218.26
8.2.170.0070.01122.96
8.2.160.0070.00720.57
8.2.150.0000.00824.18
8.2.140.0000.00824.66
8.2.130.0060.00320.83
8.2.120.0060.00326.35
8.2.110.0070.00421.00
8.2.100.0030.00817.97
8.2.90.0030.00517.95
8.2.80.0000.01017.97
8.2.70.0040.00417.75
8.2.60.0070.00418.03
8.2.50.0030.00518.07
8.2.40.0040.00420.83
8.2.30.0000.00820.73
8.2.20.0080.00017.73
8.2.10.0070.00018.09
8.2.00.0030.00618.11
8.1.280.0070.00725.92
8.1.270.0030.00620.63
8.1.260.0000.00728.09
8.1.250.0080.00028.09
8.1.240.0060.00322.57
8.1.230.0040.00720.89
8.1.220.0040.00417.74
8.1.210.0080.00018.96
8.1.200.0100.00017.48
8.1.190.0000.00817.13
8.1.180.0050.00318.10
8.1.170.0040.00418.46
8.1.160.0040.00420.81
8.1.150.0000.00718.99
8.1.140.0060.00319.49
8.1.130.0030.00317.79
8.1.120.0040.00417.50
8.1.110.0050.00317.38
8.1.100.0000.00817.40
8.1.90.0060.00617.49
8.1.80.0030.00517.54
8.1.70.0000.00717.50
8.1.60.0030.00617.62
8.1.50.0000.00817.43
8.1.40.0060.00317.53
8.1.30.0030.00517.70
8.1.20.0000.00817.64
8.1.10.0050.00217.63
8.1.00.0040.00417.59
8.0.300.0000.00719.98
8.0.290.0000.00816.75
8.0.280.0000.00718.42
8.0.270.0000.00717.30
8.0.260.0040.00417.33
8.0.250.0050.00217.13
8.0.240.0070.00016.95
8.0.230.0030.00317.04
8.0.220.0070.00017.06
8.0.210.0000.00716.91
8.0.200.0030.00316.92
8.0.190.0000.00817.12
8.0.180.0040.00417.02
8.0.170.0040.00416.93
8.0.160.0040.00417.07
8.0.150.0040.00416.96
8.0.140.0000.01116.95
8.0.130.0030.00313.46
8.0.120.0040.00416.85
8.0.110.0040.00417.02
8.0.100.0030.00516.91
8.0.90.0070.00016.86
8.0.80.0100.00716.93
8.0.70.0000.00716.85
8.0.60.0030.00516.82
8.0.50.0080.00016.82
8.0.30.0100.00917.01
8.0.20.0090.01017.40
8.0.10.0040.00416.95
8.0.00.0130.00516.92
7.4.330.0050.00016.78
7.4.320.0000.00716.62
7.4.300.0000.00616.55
7.4.290.0080.00016.43
7.4.280.0040.00416.54
7.4.270.0000.00716.48
7.4.260.0000.00716.62
7.4.250.0080.00016.61
7.4.240.0040.00416.48
7.4.230.0000.00716.62
7.4.220.0120.00616.71
7.4.210.0070.00716.61
7.4.200.0030.00316.43
7.4.160.0180.00616.42
7.4.150.0150.00317.40
7.4.140.0130.00617.86
7.4.130.0110.00616.54
7.4.120.0110.00716.56
7.4.110.0120.01216.66
7.4.100.0090.01216.57
7.4.90.0080.01616.59
7.4.80.0100.01019.39
7.4.70.0070.01016.60
7.4.60.0030.01316.74
7.4.50.0070.00916.51
7.4.40.0120.00916.52
7.4.30.0140.00316.75
7.4.10.0030.01515.18
7.4.00.0100.00614.96
7.3.330.0000.00513.31
7.3.320.0050.00013.34
7.3.310.0000.00716.49
7.3.300.0070.00016.53
7.3.290.0060.00016.52
7.3.280.0080.00916.49
7.3.270.0110.00817.40
7.3.260.0120.01216.39
7.3.250.0070.01116.47
7.3.240.0090.01016.49
7.3.230.0090.00916.68
7.3.210.0110.00616.54
7.3.200.0100.00616.39
7.3.190.0130.00416.73
7.3.180.0070.01016.57
7.3.170.0060.01516.50
7.3.160.0080.00816.38
7.3.130.0040.01214.88
7.3.120.0070.01114.98
7.3.110.0090.00914.80
7.3.100.0080.00514.93
7.3.90.0070.01215.02
7.3.80.0040.00914.99
7.3.70.0080.00314.68
7.3.60.0050.00814.78
7.3.50.0060.00414.76
7.3.40.0030.00814.79
7.3.30.0080.00614.76
7.3.20.0080.00616.57
7.3.10.0090.00516.78
7.3.00.0050.01016.61
7.2.330.0140.00916.82
7.2.320.0090.00916.74
7.2.310.0070.01016.57
7.2.300.0090.00916.82
7.2.290.0140.01016.82
7.2.260.0070.01115.40
7.2.250.0060.01214.87
7.2.240.0100.00415.26
7.2.230.0080.00615.09
7.2.220.0020.01215.14
7.2.210.0060.00814.98
7.2.200.0040.00615.12
7.2.190.0110.00315.13
7.2.180.0030.00715.23
7.2.170.0020.01215.13
7.2.160.0030.00715.01
7.2.150.0000.01617.09
7.2.140.0070.00716.95
7.2.130.0060.00317.03
7.2.120.0070.01016.68
7.2.110.0060.00916.69
7.2.100.0040.01216.91
7.2.90.0070.00417.05
7.2.80.0060.00617.11
7.2.70.0070.01117.13
7.2.60.0060.00816.70
7.2.50.0120.00616.80
7.2.40.0090.00916.86
7.2.30.0040.01116.86
7.2.20.0100.00317.04
7.2.10.0060.00916.78
7.2.00.0030.00818.06
7.1.330.0030.01216.04
7.1.320.0050.01415.89
7.1.310.0030.01115.77
7.1.300.0060.01015.76
7.1.290.0070.00515.68
7.1.280.0000.01315.78
7.1.270.0080.00715.82
7.1.260.0030.01015.88
7.1.250.0070.00716.02
7.1.240.0070.00715.99
7.1.230.0060.00615.93
7.1.220.0060.00615.77
7.1.210.0060.00615.71
7.1.200.0040.00715.78
7.1.190.0040.01115.77
7.1.180.0100.00315.94
7.1.170.0120.00015.63
7.1.160.0090.00616.04
7.1.150.0070.00715.69
7.1.140.0000.01415.72
7.1.130.0060.00915.89
7.1.120.0090.00316.03
7.1.110.0030.00715.87
7.1.100.0050.01016.96
7.1.90.0140.00315.80
7.1.80.0070.00715.98
7.1.70.0030.00716.38
7.1.60.0050.01317.38
7.1.50.0050.01016.50
7.1.40.0070.00715.53
7.1.30.0070.00315.87
7.1.20.0000.00915.65
7.1.10.0080.00016.02
7.1.00.0040.04219.05
7.0.330.0070.00715.12
7.0.320.0030.00615.22
7.0.310.0090.00915.41
7.0.300.0070.01015.40
7.0.290.0040.00715.51
7.0.280.0060.00615.49
7.0.270.0050.00515.52
7.0.260.0000.01115.55
7.0.250.0070.00715.59
7.0.240.0030.00915.19
7.0.230.0050.00315.64
7.0.220.0000.00815.46
7.0.210.0000.01215.40
7.0.200.0060.00516.20
7.0.190.0100.00315.45
7.0.180.0030.00915.47
7.0.170.0110.00315.53
7.0.160.0000.01415.36
7.0.150.0090.00315.36
7.0.140.0000.01115.55
7.0.130.0070.01015.44
7.0.120.0090.00015.54
7.0.110.0070.00715.18
7.0.100.0090.00915.23
7.0.90.0040.01215.20
7.0.80.0030.00615.41
7.0.70.0070.00415.44
7.0.60.0090.04217.63
7.0.50.0070.03516.83
7.0.40.0070.03516.88
7.0.30.0140.04416.77
7.0.20.0170.04216.89
7.0.10.0120.04016.86
7.0.00.0050.02416.84
5.6.400.0000.00914.38
5.6.390.0060.00614.53
5.6.380.0030.00914.55
5.6.370.0030.01014.59
5.6.360.0000.01014.46
5.6.350.0070.00714.70
5.6.340.0030.01014.28
5.6.330.0070.00314.55
5.6.320.0030.00914.75
5.6.310.0000.01514.66
5.6.300.0070.00314.54
5.6.290.0050.00314.62
5.6.280.0040.02017.80
5.6.270.0030.00914.58
5.6.260.0040.01114.61
5.6.250.0090.00614.50
5.6.240.0030.00614.79
5.6.230.0070.00714.63
5.6.220.0100.00714.52
5.6.210.0020.03417.59
5.6.200.0050.02316.36
5.6.190.0080.02517.55
5.6.180.0150.02717.51
5.6.170.0130.03717.51
5.6.160.0080.04017.43
5.6.150.0060.02916.52
5.6.140.0030.02716.39
5.6.130.0120.04216.38
5.6.120.0070.04717.66
5.6.110.0050.02217.61
5.6.100.0050.02617.64
5.6.90.0070.02817.61
5.6.80.0040.03717.39
5.6.70.0000.00914.43
5.6.60.0000.01214.62
5.6.50.0110.00714.18
5.6.40.0100.00714.21
5.6.30.0000.00814.33
5.6.20.0100.00014.16
5.6.10.0070.00714.30
5.6.00.0030.00714.34
5.5.380.0040.00714.69
5.5.370.0050.00514.18
5.5.360.0030.00614.34
5.5.350.1980.02217.45
5.5.340.0100.03916.16
5.5.330.0070.03617.45
5.5.320.0130.04717.28
5.5.310.0120.04217.42
5.5.300.0090.03916.18
5.5.290.0090.03416.26
5.5.280.0100.03117.63
5.5.270.0040.02517.65
5.5.260.0000.03917.69
5.5.250.0050.02317.66
5.5.240.0150.02717.41
5.5.230.0000.01114.38
5.5.220.0000.01314.16
5.5.210.0040.01114.48
5.5.200.0030.01414.51
5.5.190.0040.00414.42
5.5.180.0030.00614.52
5.5.170.0050.00514.58
5.5.160.0060.00614.43
5.5.150.0070.01014.43
5.5.140.0030.01314.31
5.5.130.0070.00713.93
5.5.120.0000.01414.13
5.5.110.0030.00614.47
5.5.100.0040.00414.59
5.5.90.0040.01114.25
5.5.80.0100.00314.48
5.5.70.0000.00914.63
5.5.60.0130.00014.59
5.5.50.0040.00714.17
5.5.40.0090.00314.46
5.5.30.0000.01814.63
5.5.20.0060.00914.46
5.5.10.0140.00014.34
5.5.00.0000.01514.33

preferences:
78.88 ms | 401 KiB | 5 Q