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; } var_dump($parent); $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('test2'); } 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) { echo $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.40.0150.00318.97
8.3.30.0070.00718.85
8.3.20.0040.00420.34
8.3.10.0100.00023.66
8.3.00.0080.00019.79
8.2.170.0120.00322.96
8.2.160.0090.00619.46
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0050.00321.00
8.2.120.0090.00026.35
8.2.110.0080.00320.89
8.2.100.0040.00818.03
8.2.90.0040.00419.17
8.2.80.0000.00817.97
8.2.70.0050.00517.63
8.2.60.0060.00317.93
8.2.50.0060.00318.07
8.2.40.0050.00319.28
8.2.30.0000.00720.67
8.2.20.0040.00417.85
8.2.10.0070.00018.04
8.2.00.0000.00718.14
8.1.270.0060.00320.83
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0030.00719.15
8.1.230.0080.00417.76
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0080.00317.50
8.1.190.0030.00517.48
8.1.180.0040.00418.10
8.1.170.0030.00618.70
8.1.160.0050.00220.88
8.1.150.0040.00419.00
8.1.140.0040.00419.63
8.1.130.0000.00717.71
8.1.120.0050.00217.52
8.1.110.0000.00717.40
8.1.100.0040.00417.41
8.1.90.0080.00017.48
8.1.80.0000.00817.46
8.1.70.0040.00417.36
8.1.60.0000.00817.53
8.1.50.0000.00817.59
8.1.40.0030.00517.44
8.1.30.0080.00017.70
8.1.20.0000.00717.68
8.1.10.0080.00017.65
8.1.00.0000.00817.46
8.0.300.0000.00718.77
8.0.290.0070.00016.88
8.0.280.0000.00718.52
8.0.270.0040.00417.31
8.0.260.0000.00617.30
8.0.250.0030.00316.97
8.0.240.0040.00417.11
8.0.230.0080.00017.11
8.0.220.0020.00516.97
8.0.210.0040.00417.01
8.0.200.0000.00617.02
8.0.190.0040.00416.97
8.0.180.0000.00716.97
8.0.170.0050.00316.86
8.0.160.0040.00417.05
8.0.150.0060.00316.90
8.0.140.0000.00816.98
8.0.130.0030.00313.51
8.0.120.0040.00416.97
8.0.110.0000.00816.99
8.0.100.0040.00416.98
8.0.90.0040.00416.96
8.0.80.0040.01116.95
8.0.70.0080.00016.95
8.0.60.0040.00417.12
8.0.50.0000.00816.97
8.0.30.0120.00817.08
8.0.20.0130.00817.40
8.0.10.0080.00017.19
8.0.00.0100.00916.88
7.4.330.0000.00516.63
7.4.320.0060.00016.64
7.4.300.0030.00316.41
7.4.290.0000.00716.55
7.4.280.0000.00916.62
7.4.270.0000.00716.69
7.4.260.0030.00516.52
7.4.250.0020.00516.43
7.4.240.0050.00316.59
7.4.230.0040.00416.35
7.4.220.0110.00816.67
7.4.210.0060.00916.76
7.4.200.0000.00716.62
7.4.160.0090.00616.57
7.4.150.0140.00417.40
7.4.140.0120.01217.86
7.4.130.0100.00916.64
7.4.120.0100.00716.67
7.4.110.0180.00016.52
7.4.100.0110.00716.43
7.4.90.0230.02616.59
7.4.80.0110.01019.39
7.4.70.0170.00316.71
7.4.60.0060.00916.41
7.4.50.0070.01116.60
7.4.40.0160.00616.36
7.4.30.0100.01316.69
7.4.00.0060.00314.96
7.3.330.0050.00013.29
7.3.320.0000.00513.47
7.3.310.0000.00816.53
7.3.300.0070.00016.34
7.3.290.0040.01016.45
7.3.280.0080.00916.46
7.3.270.0110.00717.40
7.3.260.0060.01216.45
7.3.250.0110.00916.46
7.3.240.0090.00816.65
7.3.230.0170.00016.46
7.3.210.0060.01016.46
7.3.200.0180.00416.50
7.3.190.0140.00416.71
7.3.180.0060.01516.54
7.3.170.0130.00816.48
7.3.160.0140.00816.44
7.2.330.0060.01216.83
7.2.320.0060.01316.82
7.2.310.0170.00016.49
7.2.300.0110.00616.51
7.2.290.0070.01216.76
7.2.60.0070.00716.81
7.2.00.0030.00919.55
7.1.200.0120.00615.77
7.1.100.0030.00918.25
7.1.70.0000.01117.09
7.1.60.0070.01119.13
7.1.50.0070.01316.98
7.1.00.0000.08022.30
7.0.200.0000.01016.77
7.0.60.0030.04020.01
7.0.50.0000.04317.89
7.0.40.0070.06720.14
7.0.30.0130.04320.34
7.0.20.0200.08020.33
7.0.10.0100.05020.20
7.0.00.0000.05020.15
5.6.280.0070.04020.84
5.6.210.0030.09020.46
5.6.200.0130.07018.29
5.6.190.0130.03720.61
5.6.180.0230.04720.48
5.6.170.0100.04720.55
5.6.160.0000.04720.52
5.6.150.0070.06018.19
5.6.140.0170.06018.18
5.6.130.0070.04718.21
5.6.120.0030.06320.90
5.6.110.0130.05321.13
5.6.100.0100.06720.98
5.6.90.0030.08021.08
5.6.80.0070.05020.50
5.5.350.0300.07320.48
5.5.340.0000.05017.93
5.5.330.0070.04720.19
5.5.320.0400.04320.38
5.5.310.0170.04020.36
5.5.300.0030.05717.98
5.5.290.0130.07018.05
5.5.280.0070.08320.79
5.5.270.0070.08320.80
5.5.260.0070.04020.77
5.5.250.0130.07320.59
5.5.240.0130.08320.17

preferences:
43.24 ms | 400 KiB | 5 Q