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('test'); } 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] = []; print_r($this->roots); } public function getChildren($parent) { $node = $this->findNode($parent, $this->roots); if(!isset($node)) { throw new InvalidArgumentException('test2'); } 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 $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('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.0040.01118.40
8.3.50.0110.00722.11
8.3.40.0060.00918.99
8.3.30.0110.00418.86
8.3.20.0030.00520.29
8.3.10.0070.00021.93
8.3.00.0040.00419.97
8.2.180.0080.00818.38
8.2.170.0140.00722.96
8.2.160.0120.00319.33
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0090.00020.98
8.2.120.0000.00826.35
8.2.110.0060.00320.52
8.2.100.0060.00618.03
8.2.90.0040.00417.75
8.2.80.0090.00017.97
8.2.70.0050.00317.93
8.2.60.0020.00517.92
8.2.50.0080.00018.10
8.2.40.0000.00820.43
8.2.30.0050.00220.77
8.2.20.0000.00717.67
8.2.10.0000.00818.20
8.2.00.0000.00718.16
8.1.280.0030.01425.92
8.1.270.0040.00420.60
8.1.260.0040.00428.09
8.1.250.0050.00328.09
8.1.240.0060.00323.96
8.1.230.0000.01120.79
8.1.220.0030.00517.77
8.1.210.0040.00422.05
8.1.200.0030.00717.35
8.1.190.0090.00017.35
8.1.180.0000.00918.10
8.1.170.0030.00518.71
8.1.160.0050.00220.86
8.1.150.0040.00418.88
8.1.140.0060.00317.38
8.1.130.0030.00517.71
8.1.120.0080.00017.53
8.1.110.0000.00817.39
8.1.100.0000.00917.52
8.1.90.0030.00517.52
8.1.80.0040.00417.48
8.1.70.0070.00017.39
8.1.60.0050.00317.51
8.1.50.0000.00917.46
8.1.40.0060.00317.62
8.1.30.0040.00417.65
8.1.20.0000.00717.56
8.1.10.0050.00317.63
8.1.00.0000.00717.57
8.0.300.0070.00019.78
8.0.290.0030.00616.88
8.0.280.0040.00418.54
8.0.270.0070.00016.88
8.0.260.0000.00617.30
8.0.250.0070.00016.95
8.0.240.0040.00417.05
8.0.230.0030.00517.01
8.0.220.0030.00317.00
8.0.210.0070.00016.95
8.0.200.0000.00716.87
8.0.190.0000.00917.06
8.0.180.0000.00716.83
8.0.170.0000.00816.95
8.0.160.0060.00316.93
8.0.150.0000.00816.77
8.0.140.0110.00016.86
8.0.130.0000.00513.33
8.0.120.0040.00416.89
8.0.110.0040.00416.81
8.0.100.0070.00016.89
8.0.90.0040.00416.94
8.0.80.0090.00916.96
8.0.70.0000.00816.81
8.0.60.0040.00416.83
8.0.50.0040.00416.82
8.0.30.0130.00817.10
8.0.20.0110.00917.40
8.0.10.0040.00417.02
8.0.00.0100.00916.68
7.4.330.0060.00016.70
7.4.320.0030.00316.54
7.4.300.0040.00416.67
7.4.290.0070.00016.55
7.4.280.0030.00616.60
7.4.270.0070.00016.57
7.4.260.0040.00416.61
7.4.250.0000.00716.43
7.4.240.0050.00216.56
7.4.230.0000.00716.39
7.4.220.0140.00316.57
7.4.210.0060.01216.67
7.4.200.0050.00216.66
7.4.160.0030.01316.81
7.4.150.0100.01417.40
7.4.140.0090.01417.86
7.4.130.0110.00816.59
7.4.120.0130.00416.61
7.4.110.0110.00716.46
7.4.100.0040.01816.74
7.4.90.0120.01216.55
7.4.80.0100.01319.39
7.4.70.0130.01016.52
7.4.60.0130.00316.64
7.4.50.0130.00316.55
7.4.40.0070.01616.32
7.4.30.0080.00816.27
7.4.00.0070.01115.09
7.3.330.0020.00213.39
7.3.320.0050.00013.28
7.3.310.0030.00316.31
7.3.300.0020.00516.40
7.3.290.0070.00816.40
7.3.280.0100.00816.43
7.3.270.0140.00317.40
7.3.260.0160.00916.44
7.3.250.0120.00716.59
7.3.240.0120.00516.39
7.3.230.0070.01616.39
7.3.210.0100.00716.63
7.3.200.0130.00316.72
7.3.190.0170.00016.68
7.3.180.0100.00616.57
7.3.170.0100.00616.44
7.3.160.0090.00816.72
7.3.10.0040.01116.82
7.3.00.0030.00716.46
7.2.330.0100.01616.85
7.2.320.0080.01216.79
7.2.310.0120.00916.77
7.2.300.0060.01116.67
7.2.290.0030.01516.89
7.2.130.0030.00916.43
7.2.120.0030.00617.02
7.2.110.0120.00617.04
7.2.100.0000.01116.91
7.2.90.0050.00516.81
7.2.80.0000.00916.89
7.2.70.0090.00617.00
7.2.60.0030.00916.86
7.2.50.0090.00316.67
7.2.40.0070.00716.94
7.2.30.0000.01416.90
7.2.20.0060.00616.90
7.2.10.0120.00316.66
7.2.00.0050.01318.03
7.1.250.0100.00315.80
7.1.100.0000.01318.24
7.1.70.0040.00416.73
7.1.60.0060.01819.13
7.1.50.0030.01717.14
7.1.00.0070.07322.46
7.0.200.0040.00416.58
7.0.100.0100.07320.00
7.0.90.0070.07719.98
7.0.80.0430.07319.97
7.0.70.0230.07319.89
7.0.60.0070.07019.96
7.0.50.0070.04720.20
7.0.40.0030.04020.09
7.0.30.0100.04320.15
7.0.20.0130.06720.13
7.0.10.0070.08020.09
7.0.00.0070.06319.99
5.6.280.0000.07021.04
5.6.250.0000.05320.60
5.6.240.0100.07720.52
5.6.230.0030.05020.67
5.6.220.0030.08720.48
5.6.210.0000.04320.64
5.6.200.0070.05720.93
5.6.190.0070.04021.11
5.6.180.0070.05721.18
5.6.170.0100.03321.05
5.6.160.0130.03721.03
5.6.150.0030.08321.07
5.6.140.0070.05320.95
5.6.130.0100.03720.96
5.6.120.0070.04321.10
5.6.110.0100.08021.11
5.6.100.0170.07321.04
5.6.90.0030.05721.05
5.6.80.0130.05020.50
5.6.70.0070.06320.47
5.6.60.0100.07020.34
5.6.50.0070.04320.33
5.6.40.0100.08020.40
5.6.30.0100.07320.45
5.6.20.0100.07320.46
5.6.10.0170.06720.32
5.6.00.0070.04720.36
5.5.380.0100.06320.45
5.5.370.0030.04720.50
5.5.360.0070.09020.35
5.5.350.0000.07020.34
5.5.340.0000.08320.93
5.5.330.0030.04020.88
5.5.320.0100.05720.90
5.5.310.0100.08020.84
5.5.300.0100.07720.95
5.5.290.0030.05720.87
5.5.280.0000.07020.94
5.5.270.0030.08320.93
5.5.260.0070.04320.92
5.5.250.0070.09020.55
5.5.240.0100.07320.13
5.5.230.0170.07320.27
5.5.220.0030.06020.16
5.5.210.0130.07320.31
5.5.200.0130.06720.29
5.5.190.0070.06720.25
5.5.180.0100.08020.20
5.5.160.0130.05020.20
5.5.150.0070.05020.00
5.5.140.0030.07720.13
5.5.130.0100.03720.29
5.5.120.0030.05020.26
5.5.110.0030.04720.26
5.5.100.0070.05320.08
5.5.90.0100.05720.17
5.5.80.0100.07320.15
5.5.70.0100.07020.11
5.5.60.0130.05320.08
5.5.50.0170.06320.11
5.5.40.0130.05320.05
5.5.30.0030.08320.09
5.5.20.0070.06720.04
5.5.10.0030.04720.07
5.5.00.0130.04720.04

preferences:
32.87 ms | 401 KiB | 5 Q