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(); } if ($parent === null) { $this->roots[$category] = []; return; } echo $parent; echo 'test'; $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(); } return array_keys($node); } public function findNode($node, &$root) { print_r(array_keys($root)); if (in_array($node, array_keys($root))) { return $root[$node]; } foreach ($root as $n) { return $this->findNode($node, $n); } } public function categoryExists($nodes, $category) { $exists = false; foreach($nodes as $node) { if (in_array($category, $this->getChildren($node))) { 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.0110.00418.68
8.3.50.0110.00822.05
8.3.40.0070.00718.84
8.3.30.0000.01418.83
8.3.20.0060.00320.21
8.3.10.0050.00223.65
8.3.00.0050.00319.98
8.2.180.0150.00616.50
8.2.170.0140.00022.96
8.2.160.0090.00620.52
8.2.150.0000.00824.18
8.2.140.0030.00524.66
8.2.130.0000.01020.94
8.2.120.0040.00426.35
8.2.110.0090.00022.23
8.2.100.0040.00817.84
8.2.90.0060.00319.34
8.2.80.0100.00017.97
8.2.70.0070.00317.75
8.2.60.0030.00617.93
8.2.50.0030.00618.07
8.2.40.0080.00020.98
8.2.30.0070.00020.59
8.2.20.0000.00817.86
8.2.10.0000.00818.08
8.2.00.0000.00718.04
8.1.280.0040.01225.92
8.1.270.0060.00320.82
8.1.260.0030.00528.09
8.1.250.0050.00328.09
8.1.240.0000.00920.86
8.1.230.0030.00920.98
8.1.220.0040.00417.78
8.1.210.0000.00918.77
8.1.200.0040.00417.36
8.1.190.0030.00617.23
8.1.180.0060.00318.10
8.1.170.0050.00318.39
8.1.160.0040.00420.71
8.1.150.0000.00718.85
8.1.140.0000.00919.63
8.1.130.0030.00317.78
8.1.120.0040.00417.46
8.1.110.0030.00617.41
8.1.100.0030.00617.52
8.1.90.0000.00717.44
8.1.80.0040.00417.57
8.1.70.0030.00317.50
8.1.60.0020.00517.53
8.1.50.0050.00317.46
8.1.40.0030.00617.41
8.1.30.0040.00417.68
8.1.20.0060.00317.69
8.1.10.0000.00817.64
8.1.00.0050.00317.60
8.0.300.0030.00618.77
8.0.290.0060.00317.00
8.0.280.0030.00318.42
8.0.270.0030.00317.29
8.0.260.0000.00717.34
8.0.250.0070.00017.07
8.0.240.0040.00417.09
8.0.230.0070.00016.94
8.0.220.0000.00716.89
8.0.210.0000.00716.96
8.0.200.0000.00717.03
8.0.190.0050.00317.02
8.0.180.0000.00816.95
8.0.170.0040.00416.96
8.0.160.0070.00017.01
8.0.150.0000.00816.98
8.0.140.0040.00416.91
8.0.130.0000.00613.42
8.0.120.0050.00317.01
8.0.110.0040.00417.03
8.0.100.0030.00617.06
8.0.90.0000.00717.03
8.0.80.0030.01217.06
8.0.70.0030.00516.94
8.0.60.0080.00016.88
8.0.50.0070.00016.85
8.0.30.0110.00917.06
8.0.20.0130.00617.40
8.0.10.0030.00516.98
8.0.00.0090.01016.79
7.4.330.0050.00016.67
7.4.320.0070.00016.53
7.4.300.0000.00716.62
7.4.290.0000.00716.69
7.4.280.0000.00816.40
7.4.270.0060.00016.55
7.4.260.0040.00416.65
7.4.250.0030.00616.63
7.4.240.0010.00616.63
7.4.230.0030.00316.29
7.4.220.0040.01316.45
7.4.210.0000.01516.50
7.4.200.0030.00316.43
7.4.160.0130.00316.62
7.4.150.0160.00317.40
7.4.140.0120.01317.86
7.4.130.0110.00816.68
7.4.120.0050.01316.54
7.4.110.0090.00916.69
7.4.100.0090.00916.57
7.4.90.0070.01016.55
7.4.80.0140.00619.39
7.4.70.0040.01216.57
7.4.60.0070.01016.57
7.4.50.0100.00516.75
7.4.40.0120.00616.69
7.4.30.0140.00316.50
7.4.00.0040.01115.08
7.3.330.0000.00613.20
7.3.320.0000.00613.51
7.3.310.0030.00316.51
7.3.300.0060.00016.57
7.3.290.0060.01116.45
7.3.280.0120.00816.45
7.3.270.0150.00317.40
7.3.260.0110.00716.59
7.3.250.0130.00716.40
7.3.240.0110.00616.51
7.3.230.0110.00516.57
7.3.210.0090.00916.52
7.3.200.0080.00816.70
7.3.190.0130.01016.44
7.3.180.0350.01816.64
7.3.170.0030.01816.38
7.3.160.0030.01316.47
7.2.330.0120.00616.89
7.2.320.0150.00716.94
7.2.310.0140.00316.62
7.2.300.0100.00716.66
7.2.290.0090.01216.89
7.2.60.0090.00616.80
7.2.00.0140.00019.46
7.1.200.0130.00715.77
7.1.100.0000.01018.27
7.1.70.0080.00017.23
7.1.60.0000.01119.13
7.1.50.0040.01917.07
7.1.00.0030.08022.40
7.0.200.0020.00516.80
7.0.100.0100.03719.98
7.0.90.0070.03719.92
7.0.80.0030.04019.96
7.0.70.0030.05019.93
7.0.60.0170.03719.97
7.0.50.0030.06320.34
7.0.40.0170.07320.14
7.0.30.0100.05020.19
7.0.20.0100.05320.14
7.0.10.0070.08320.10
7.0.00.0070.05320.18
5.6.280.0030.03321.03
5.6.250.0030.08020.74
5.6.240.0030.06020.64
5.6.230.0070.03720.52
5.6.220.0100.04320.50
5.6.210.0070.03320.67
5.6.200.0100.09020.96
5.6.190.0100.08320.98
5.6.180.0170.07020.95
5.6.170.0100.08321.10
5.6.160.0030.07721.06
5.6.150.0100.07021.09
5.6.140.0070.05721.12
5.6.130.0170.07720.95
5.6.120.0170.07721.18
5.6.110.0100.05321.11
5.6.100.0030.07021.05
5.6.90.0030.08020.93
5.6.80.0130.05720.41
5.6.70.0130.05020.53
5.6.60.0170.07320.32
5.6.50.0100.07720.48
5.6.40.0130.07320.50
5.6.30.0030.07320.41
5.6.20.0000.08720.54
5.6.10.0030.08020.39
5.6.00.0130.07720.48
5.5.380.0030.05320.38
5.5.370.0000.04320.39
5.5.360.0100.03320.36
5.5.350.0000.07720.39
5.5.340.0070.07320.80
5.5.330.0130.07020.79
5.5.320.0130.07720.93
5.5.310.0130.07320.93
5.5.300.0070.07720.81
5.5.290.0070.05320.84
5.5.280.0070.08720.66
5.5.270.0100.08020.92
5.5.260.0100.07720.89
5.5.250.0100.08320.74
5.5.240.0070.07020.26
5.5.230.0130.07320.02
5.5.220.0130.07320.16
5.5.210.0100.04720.03
5.5.200.0130.06020.27
5.5.190.0100.08020.23
5.5.180.0100.06320.14
5.5.160.0070.08020.01
5.5.150.0070.07720.20
5.5.140.0130.05720.09
5.5.130.0030.09020.26
5.5.120.0100.07320.25
5.5.110.0030.08320.09
5.5.100.0070.08020.14
5.5.90.0030.07719.93
5.5.80.0170.06320.17
5.5.70.0170.07020.09
5.5.60.0100.07019.98
5.5.50.0100.07720.03
5.5.40.0070.08020.17
5.5.30.0070.08320.09
5.5.20.0230.06020.16
5.5.10.0070.08020.09
5.5.00.0130.07319.96
5.4.450.0130.07019.37
5.4.440.0100.07719.43
5.4.430.0130.07719.19
5.4.420.0070.07719.48
5.4.410.0070.08719.32
5.4.400.0170.06719.19
5.4.390.0170.07018.95
5.4.380.0000.08318.88
5.4.370.0100.07719.13
5.4.360.0070.08018.95
5.4.350.0070.06718.90
5.4.340.0070.05319.03
5.4.320.0000.07018.86
5.4.310.0030.04019.04
5.4.300.0130.07019.05
5.4.290.0230.05318.88
5.4.280.0030.08319.04
5.4.270.0130.04719.22
5.4.260.0030.07319.21
5.4.250.0100.07318.94
5.4.240.0070.08019.03
5.4.230.0100.07019.03
5.4.220.0070.07719.07
5.4.210.0030.08318.87
5.4.200.0070.07019.09
5.4.190.0130.06719.12
5.4.180.0130.06718.90
5.4.170.0100.07719.09
5.4.160.0130.07319.02
5.4.150.0030.05018.80
5.4.140.0030.08016.32
5.4.130.0000.07716.41
5.4.120.0170.03316.42
5.4.110.0030.07016.33
5.4.100.0070.06016.52
5.4.90.0100.06316.50
5.4.80.0070.06716.45
5.4.70.0030.07016.31
5.4.60.0030.03716.37
5.4.50.0130.06716.49
5.4.40.0070.07716.37
5.4.30.0000.07716.39
5.4.20.0130.07016.32
5.4.10.0070.07316.37
5.4.00.0030.05015.86
5.3.290.0130.07014.62
5.3.280.0100.05014.56
5.3.270.0130.07014.56
5.3.260.0030.07014.61
5.3.250.0030.07714.58
5.3.240.0070.04714.62
5.3.230.0070.05314.58
5.3.220.0000.08314.63
5.3.210.0130.06714.66
5.3.200.0100.07014.70
5.3.190.0030.05714.50
5.3.180.0070.07014.65
5.3.170.0100.07314.67
5.3.160.0000.05014.62
5.3.150.0000.05014.63
5.3.140.0000.06014.69
5.3.130.0070.07714.52
5.3.120.0030.08014.57
5.3.110.0100.06714.50
5.3.100.0070.05014.24
5.3.90.0070.06014.24
5.3.80.0030.07714.24
5.3.70.0030.07014.24
5.3.60.0030.08014.24
5.3.50.0030.06014.24
5.3.40.0100.07014.24
5.3.30.0000.07714.24
5.3.20.0030.07014.24
5.3.10.0100.07014.24
5.3.00.0200.06014.24
5.2.170.0100.05714.24
5.2.160.0030.06314.24
5.2.150.0070.04714.24
5.2.140.0030.05714.24
5.2.130.0100.05714.24
5.2.120.0100.05714.24
5.2.110.0100.05714.24
5.2.100.0070.05714.24
5.2.90.0000.06314.24
5.2.80.0030.06014.24
5.2.70.0100.06014.24
5.2.60.0100.05314.24
5.2.50.0070.06314.24
5.2.40.0030.06014.24
5.2.30.0030.06014.24
5.2.20.0030.06014.24
5.2.10.0070.06014.24
5.2.00.0070.05714.24
5.1.60.0030.05714.24
5.1.50.0030.05314.24
5.1.40.0070.05314.24
5.1.30.0070.05314.24
5.1.20.0030.05714.24
5.1.10.0070.03714.24
5.1.00.0000.04714.24
5.0.50.0030.04714.24
5.0.40.0070.03714.24
5.0.30.0070.06014.24
5.0.20.0070.04014.24
5.0.10.0170.02714.24
5.0.00.0070.05714.24
4.4.90.0030.03314.24
4.4.80.0070.03314.24
4.4.70.0000.03714.24
4.4.60.0030.02714.24
4.4.50.0000.03714.24
4.4.40.0030.05314.24
4.4.30.0030.03314.24
4.4.20.0000.03314.24
4.4.10.0000.03714.24
4.4.00.0070.04714.24
4.3.110.0030.03014.24
4.3.100.0000.03314.24
4.3.90.0000.03714.24
4.3.80.0000.03014.24
4.3.70.0000.02014.24
4.3.60.0000.03714.24
4.3.50.0000.02014.24
4.3.40.0000.04714.24
4.3.30.0030.03314.24
4.3.20.0000.02314.24
4.3.10.0000.03714.24
4.3.00.0000.03714.24

preferences:
49.68 ms | 401 KiB | 5 Q