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('B', 'A'); $c->addCategory('A', '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.0070.00716.49
8.3.50.0120.00621.92
8.3.40.0120.00918.82
8.3.30.0000.01418.67
8.3.20.0040.00420.01
8.3.10.0050.00323.66
8.3.00.0080.00019.98
8.2.180.0130.01018.29
8.2.170.0150.00022.96
8.2.160.0070.01020.57
8.2.150.0050.00324.18
8.2.140.0050.00324.66
8.2.130.0040.00420.95
8.2.120.0080.00026.35
8.2.110.0040.00422.23
8.2.100.0080.00418.05
8.2.90.0040.00419.17
8.2.80.0000.00817.97
8.2.70.0080.00017.75
8.2.60.0060.00317.93
8.2.50.0040.00418.07
8.2.40.0000.00821.07
8.2.30.0050.00320.61
8.2.20.0040.00417.77
8.2.10.0070.00018.20
8.2.00.0000.00718.08
8.1.280.0080.00625.92
8.1.270.0060.00320.79
8.1.260.0000.00828.09
8.1.250.0000.00828.09
8.1.240.0060.00323.79
8.1.230.0030.00717.60
8.1.220.0000.00817.74
8.1.210.0060.00318.77
8.1.200.0030.00617.22
8.1.190.0040.00417.36
8.1.180.0060.00318.10
8.1.170.0030.00618.46
8.1.160.0040.00420.80
8.1.150.0040.00418.83
8.1.140.0040.00419.61
8.1.130.0040.00417.78
8.1.120.0040.00417.50
8.1.110.0040.00417.38
8.1.100.0000.00817.47
8.1.90.0070.00317.48
8.1.80.0040.00317.55
8.1.70.0000.00717.45
8.1.60.0000.00917.52
8.1.50.0040.00417.58
8.1.40.0090.00017.45
8.1.30.0040.00417.59
8.1.20.0080.00017.58
8.1.10.0070.00017.51
8.1.00.0000.00817.54
8.0.300.0080.00018.77
8.0.290.0000.00716.75
8.0.280.0000.00718.39
8.0.270.0030.00317.28
8.0.260.0070.00017.31
8.0.250.0000.00717.06
8.0.240.0040.00416.91
8.0.230.0030.00316.93
8.0.220.0030.00316.80
8.0.210.0050.00316.86
8.0.200.0070.00016.89
8.0.190.0040.00417.02
8.0.180.0040.00416.98
8.0.170.0000.00816.99
8.0.160.0040.00316.96
8.0.150.0050.00216.89
8.0.140.0100.00016.86
8.0.130.0000.00513.43
8.0.120.0080.00016.86
8.0.110.0030.00616.77
8.0.100.0080.00016.98
8.0.90.0070.00016.79
8.0.80.0140.00416.88
8.0.70.0040.00416.96
8.0.60.0080.00017.04
8.0.50.0040.00416.83
8.0.30.0100.00817.18
8.0.20.0110.00817.40
8.0.10.0040.00416.89
8.0.00.0080.01216.79
7.4.330.0030.00316.83
7.4.320.0070.00016.65
7.4.300.0060.00016.53
7.4.290.0000.00716.53
7.4.280.0030.00616.61
7.4.270.0050.00316.53
7.4.260.0040.00416.48
7.4.250.0030.00616.64
7.4.240.0050.00216.56
7.4.230.0000.00716.46
7.4.220.0100.01316.53
7.4.210.0060.00916.52
7.4.200.0050.00216.62
7.4.160.0100.00716.63
7.4.150.0030.01417.40
7.4.140.0130.00917.86
7.4.130.0100.01016.48
7.4.120.0130.00416.59
7.4.110.0060.01316.46
7.4.100.0090.01216.44
7.4.90.0090.00916.46
7.4.80.0060.01219.39
7.4.70.0030.01316.71
7.4.60.0090.00716.34
7.4.50.0110.00716.65
7.4.40.0040.01516.52
7.4.30.0100.00716.56
7.4.10.0040.01414.89
7.4.00.0040.01114.99
7.3.330.0000.00513.37
7.3.320.0050.00013.27
7.3.310.0050.00216.42
7.3.300.0000.00716.29
7.3.290.0050.00316.45
7.3.280.0100.01216.40
7.3.270.0110.01117.40
7.3.260.0170.00416.38
7.3.250.0080.01116.33
7.3.240.0130.00616.41
7.3.230.0130.00316.64
7.3.210.0070.01016.52
7.3.200.0070.01016.68
7.3.190.0100.00616.48
7.3.180.0060.00916.35
7.3.170.0080.00816.45
7.3.160.0120.00316.54
7.3.130.0090.00914.96
7.3.120.0120.00614.76
7.3.110.0060.01214.90
7.3.100.0070.00314.61
7.3.90.0100.00315.02
7.3.80.0000.01114.63
7.3.70.0070.00314.96
7.3.60.0070.00714.88
7.3.50.0000.00914.79
7.3.40.0030.01314.88
7.3.30.0070.00714.97
7.3.20.0060.00316.66
7.3.10.0060.00616.49
7.3.00.0120.00616.78
7.2.330.0130.00916.76
7.2.320.0030.01316.84
7.2.310.0080.00816.78
7.2.300.0070.01116.61
7.2.290.0100.01316.64
7.2.260.0110.00715.35
7.2.250.0100.00715.10
7.2.240.0040.01115.21
7.2.230.0100.00714.84
7.2.220.0030.00915.14
7.2.210.0050.00515.31
7.2.200.0100.00715.16
7.2.190.0030.01314.89
7.2.180.0040.00815.20
7.2.170.0070.01115.04
7.2.160.0050.00515.12
7.2.150.0110.00416.99
7.2.140.0070.01117.02
7.2.130.0060.00916.75
7.2.120.0030.00716.82
7.2.110.0140.00016.99
7.2.100.0100.00617.04
7.2.90.0040.01117.16
7.2.80.0030.01017.05
7.2.70.0030.01417.02
7.2.60.0080.00816.78
7.2.50.0070.01116.95
7.2.40.0040.01116.73
7.2.30.0090.00917.10
7.2.20.0140.00316.86
7.2.10.0030.00717.07
7.2.00.0090.00718.31
7.1.330.0070.01015.78
7.1.320.0090.00616.07
7.1.310.0030.00615.87
7.1.300.0030.00615.59
7.1.290.0030.00715.76
7.1.280.0080.00815.93
7.1.270.0030.00615.52
7.1.260.0060.00915.72
7.1.250.0070.00716.05
7.1.240.0070.00715.95
7.1.230.0070.01015.69
7.1.220.0070.00715.61
7.1.210.0060.00615.77
7.1.200.0070.00515.75
7.1.190.0060.00915.84
7.1.180.0000.01415.96
7.1.170.0070.00715.82
7.1.160.0070.00715.73
7.1.150.0040.00415.88
7.1.140.0060.00615.93
7.1.130.0000.01315.87
7.1.120.0000.00915.72
7.1.110.0060.00915.64
7.1.100.0060.00417.03
7.1.90.0060.00615.68
7.1.80.0030.01015.93
7.1.70.0050.00416.17
7.1.60.0080.01317.45
7.1.50.0060.01216.47
7.1.40.0070.00316.07
7.1.30.0000.01415.59
7.1.20.0030.00915.89
7.1.10.0070.00715.71
7.1.00.0020.04519.20
7.0.330.0030.01015.32
7.0.320.0070.00315.48
7.0.310.0060.00615.48
7.0.300.0060.00615.46
7.0.290.0120.00315.45
7.0.280.0080.00015.46
7.0.270.0100.00315.46
7.0.260.0040.01115.26
7.0.250.0030.00615.40
7.0.240.0090.00315.37
7.0.230.0060.00615.25
7.0.220.0060.00315.52
7.0.210.0080.00615.34
7.0.200.0050.00516.18
7.0.190.0080.00815.29
7.0.180.0090.00015.54
7.0.170.0080.00415.61
7.0.160.0000.00915.21
7.0.150.0060.00915.25
7.0.140.0070.00715.53
7.0.130.0060.00315.52
7.0.120.0030.00615.32
7.0.110.0070.00715.48
7.0.100.0050.00515.43
7.0.90.0060.00615.48
7.0.80.0110.00415.20
7.0.70.0100.00615.26
7.0.60.0100.04117.71
7.0.50.0070.04716.62
7.0.40.0090.03016.88
7.0.30.0190.03716.93
7.0.20.0130.03116.72
7.0.10.0060.04416.78
7.0.00.0050.03516.71
5.6.400.0100.00714.29
5.6.390.0040.01114.12
5.6.380.0130.00314.41
5.6.370.0000.01314.83
5.6.360.0090.00014.70
5.6.350.0060.00914.58
5.6.340.0030.00714.64
5.6.330.0030.01414.24
5.6.320.0080.00814.43
5.6.310.0040.01114.49
5.6.300.0000.01314.39
5.6.290.0030.01414.25
5.6.280.0030.02817.77
5.6.270.0080.00714.66
5.6.260.0060.00314.57
5.6.250.0100.00714.54
5.6.240.0000.01614.53
5.6.230.0030.01414.68
5.6.220.0030.01014.32
5.6.210.0090.04017.45
5.6.200.0120.04016.42
5.6.190.0090.04417.54
5.6.180.0130.02517.53
5.6.170.0140.04417.43
5.6.160.0090.03617.53
5.6.150.0080.04316.37
5.6.140.0050.02416.35
5.6.130.0050.03416.38
5.6.120.0050.04817.74
5.6.110.0030.02517.81
5.6.100.0070.04517.68
5.6.90.0100.04417.78
5.6.80.0050.02617.50
5.6.70.0100.00314.43
5.6.60.0100.00314.16
5.6.50.0030.00714.56
5.6.40.0040.00714.37
5.6.30.0080.00614.07
5.6.20.0090.00614.47
5.6.10.0120.00314.41
5.6.00.0070.00714.11
5.5.380.0100.00314.55
5.5.370.0060.00914.61
5.5.360.0120.00314.34
5.5.350.2130.02317.54
5.5.340.0100.04216.27
5.5.330.0080.04617.41
5.5.320.0130.04217.16
5.5.310.0160.04317.52
5.5.300.0030.03316.29
5.5.290.0020.05116.18
5.5.280.0030.04917.64
5.5.270.0060.03317.63
5.5.260.0120.04017.62
5.5.250.0050.02317.37
5.5.240.0160.01817.15
5.5.230.0030.01014.40
5.5.220.0040.00814.45
5.5.210.0100.00614.54
5.5.200.0070.00314.18
5.5.190.0070.00714.19
5.5.180.0030.00614.29
5.5.170.0000.01314.19
5.5.160.0070.00714.38
5.5.150.0070.01014.50
5.5.140.0000.01314.23
5.5.130.0090.00914.39
5.5.120.0030.01014.43
5.5.110.0120.00614.27
5.5.100.0030.01014.13
5.5.90.0040.00814.20
5.5.80.0060.00614.22
5.5.70.0070.00714.57
5.5.60.0040.01114.11
5.5.50.0040.01114.51
5.5.40.0070.00713.91
5.5.30.0040.00814.46
5.5.20.0000.01514.18
5.5.10.0000.01414.29
5.5.00.0030.00714.53

preferences:
52.17 ms | 401 KiB | 5 Q