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) || !$this->categoryExists($this->roots, $parent)) { throw new InvalidArgumentException(); } if ($parent === null) { $this->tree[$category] = []; } $node = $findNode($parent, $this->root); if(!isset($node)) { throw new InvalidArgumentException(); } $node[$category] = []; } public function getChildren($parent) { $node = $findNode($parent, $this->root); if(!isset($node)) { throw new InvalidArgumentException(); } return array_keys($node); } public function findNode($node, &$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.0090.00616.63
8.3.50.0120.00617.93
8.3.40.0060.01218.89
8.3.30.0040.01118.77
8.3.20.0040.00420.16
8.3.10.0000.00723.53
8.3.00.0000.00819.85
8.2.180.0100.01018.29
8.2.170.0110.01122.96
8.2.160.0030.01019.37
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0030.00620.95
8.2.120.0040.00426.16
8.2.110.0030.00620.35
8.2.100.0040.00717.93
8.2.90.0030.00519.27
8.2.80.0080.00017.97
8.2.70.0030.00717.63
8.2.60.0030.00917.93
8.2.50.0000.00818.07
8.2.40.0100.00020.97
8.2.30.0040.00420.54
8.2.20.0040.00417.79
8.2.10.0070.00018.07
8.2.00.0070.00018.05
8.1.280.0040.01125.92
8.1.270.0100.01018.93
8.1.260.0070.00026.35
8.1.250.0000.00728.09
8.1.240.0060.00617.36
8.1.230.0090.00317.73
8.1.220.0000.00817.78
8.1.210.0080.00018.77
8.1.200.0070.00317.35
8.1.190.0040.00417.23
8.1.180.0040.00418.10
8.1.170.0080.00018.54
8.1.160.0040.00420.70
8.1.150.0050.00318.84
8.1.140.0000.00819.62
8.1.130.0040.00417.65
8.1.120.0030.00317.43
8.1.110.0040.00417.49
8.1.100.0040.00417.53
8.1.90.0030.00517.50
8.1.80.0070.00017.43
8.1.70.0000.00717.53
8.1.60.0040.00417.66
8.1.50.0030.00517.58
8.1.40.0000.00817.44
8.1.30.0000.00817.59
8.1.20.0060.00317.65
8.1.10.0080.00017.63
8.1.00.0040.00417.46
8.0.300.0050.00318.77
8.0.290.0040.00416.75
8.0.280.0000.00818.48
8.0.270.0070.00017.30
8.0.260.0070.00017.32
8.0.250.0000.00616.91
8.0.240.0000.00716.90
8.0.230.0040.00417.07
8.0.220.0040.00416.97
8.0.210.0000.00716.97
8.0.200.0000.00617.05
8.0.190.0040.00417.02
8.0.180.0000.00816.98
8.0.170.0060.00317.03
8.0.160.0070.00016.88
8.0.150.0000.00716.89
8.0.140.0000.00816.96
8.0.130.0000.00613.38
8.0.120.0040.00416.88
8.0.110.0040.00417.08
8.0.100.0040.00416.95
8.0.90.0000.00717.02
8.0.80.0110.00416.98
8.0.70.0000.00717.06
8.0.60.0040.00417.02
8.0.50.0000.00716.83
8.0.30.0130.00817.16
8.0.20.0110.00817.40
8.0.10.0000.00817.10
8.0.00.0090.01116.86
7.4.330.0050.00016.83
7.4.320.0000.00716.61
7.4.300.0000.00716.50
7.4.290.0050.00316.56
7.4.280.0030.00616.57
7.4.270.0050.00216.60
7.4.260.0000.00716.50
7.4.250.0040.00416.50
7.4.240.0000.00716.61
7.4.230.0050.00316.75
7.4.220.0040.01516.71
7.4.210.0060.01316.75
7.4.200.0000.00816.75
7.4.160.0090.00916.80
7.4.150.0120.00617.40
7.4.140.0150.00817.86
7.4.130.0140.00416.62
7.4.120.0130.00516.55
7.4.110.0100.00716.55
7.4.100.0110.00616.43
7.4.90.0060.01216.39
7.4.80.0080.01519.39
7.4.70.0130.00716.52
7.4.60.0070.01116.47
7.4.50.0000.01316.55
7.4.40.0100.00716.64
7.4.30.0100.01016.69
7.4.00.0120.00414.93
7.3.330.0000.00613.19
7.3.320.0030.00313.25
7.3.310.0030.00516.28
7.3.300.0040.00416.27
7.3.290.0110.00616.36
7.3.280.0070.00916.39
7.3.270.0140.00517.40
7.3.260.0180.00016.64
7.3.250.0100.00916.48
7.3.240.0060.01316.51
7.3.230.0060.01016.71
7.3.210.0140.00316.57
7.3.200.0090.00716.32
7.3.190.0090.01516.55
7.3.180.0100.00716.37
7.3.170.0120.00416.60
7.3.160.0130.00416.54
7.3.120.0070.01114.79
7.3.110.0150.00014.38
7.3.100.0120.00415.05
7.3.90.0110.00614.96
7.3.80.0080.00614.79
7.3.70.0070.01014.75
7.3.60.0070.00715.01
7.3.50.0040.00714.96
7.3.40.0090.00914.72
7.3.30.0110.00014.71
7.3.20.0090.00616.67
7.3.10.0070.00816.41
7.3.00.0100.00316.42
7.2.330.0090.00916.69
7.2.320.0040.01516.75
7.2.310.0120.00616.75
7.2.300.0130.00916.59
7.2.290.0060.01216.84
7.2.240.0110.00714.98
7.2.230.0040.00715.18
7.2.220.0090.00615.21
7.2.210.0080.00815.26
7.2.200.0110.00415.06
7.2.190.0000.01515.06
7.2.180.0040.01215.22
7.2.170.0060.00615.16
7.2.160.0070.01114.77
7.2.150.0100.00717.08
7.2.140.0100.00317.00
7.2.130.0050.01116.85
7.2.120.0080.00616.79
7.2.110.0070.00716.73
7.2.100.0050.00916.82
7.2.90.0080.00916.83
7.2.80.0070.00616.78
7.2.70.0110.00516.80
7.2.60.0100.00716.74
7.2.50.0090.00716.76
7.2.40.0110.00416.87
7.2.30.0090.00716.85
7.2.20.0070.00716.86
7.2.10.0110.00516.90
7.2.00.0070.00717.36
7.1.330.0080.00815.92
7.1.320.0060.00315.62
7.1.310.0030.00615.84
7.1.300.0030.00615.59
7.1.290.0060.00615.98
7.1.280.0040.01215.66
7.1.270.0060.00615.76
7.1.260.0060.00615.55
7.1.250.0070.00815.56
7.1.200.0080.00415.91
7.1.100.0000.01318.01
7.1.70.0060.00617.29
7.1.60.0130.00719.13
7.1.50.0130.01016.86
7.1.00.0130.07022.33
7.0.200.1070.00716.83
7.0.60.0070.08319.95
7.0.50.0130.07317.96
7.0.40.0030.05320.27
7.0.30.0270.04720.08
7.0.20.0230.08320.07
7.0.10.0170.08020.30
7.0.00.0130.04720.18
5.6.280.0070.03021.11
5.6.210.0030.04020.66
5.6.200.0100.05018.18
5.6.190.0070.09020.55
5.6.180.0170.03720.64
5.6.170.0200.04720.41
5.6.160.0030.05720.55
5.6.150.0070.08018.25
5.6.140.0030.04018.21
5.6.130.0030.08318.27
5.6.120.0030.09020.99
5.6.110.0030.08720.90
5.6.100.0100.08321.02
5.6.90.0030.06020.98
5.6.80.0070.07320.49
5.5.350.0300.07020.34
5.5.340.0100.07717.99
5.5.330.0070.04320.21
5.5.320.0300.08720.25
5.5.310.0230.08320.23
5.5.300.0200.06017.97
5.5.290.0100.04718.04
5.5.280.0000.04320.88
5.5.270.0000.04320.88
5.5.260.0170.05720.85
5.5.250.0070.06320.61
5.5.240.0130.07720.27

preferences:
43.86 ms | 400 KiB | 5 Q