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 ($key === $category || 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('B', null); $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.00416.75
8.3.50.0070.00718.17
8.3.40.0110.01118.75
8.3.30.0160.00318.97
8.3.20.0080.00020.16
8.3.10.0040.00423.61
8.3.00.0000.00819.97
8.2.180.0090.00618.34
8.2.170.0040.01122.96
8.2.160.0140.00720.52
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0000.00821.13
8.2.120.0040.00426.35
8.2.110.0000.01120.93
8.2.100.0080.00317.91
8.2.90.0040.00419.40
8.2.80.0030.00517.97
8.2.70.0030.00617.88
8.2.60.0000.00817.93
8.2.50.0040.00418.07
8.2.40.0040.00421.12
8.2.30.0050.00320.52
8.2.20.0040.00417.84
8.2.10.0040.00418.16
8.2.00.0000.00818.27
8.1.270.0060.00319.00
8.1.260.0080.00028.09
8.1.250.0040.00428.09
8.1.240.0060.00322.10
8.1.230.0040.00819.08
8.1.220.0000.00817.78
8.1.210.0030.00618.77
8.1.200.0030.00617.48
8.1.190.0040.00417.22
8.1.180.0060.00318.10
8.1.170.0030.00618.70
8.1.160.0030.00620.79
8.1.150.0030.00518.91
8.1.140.0030.00519.56
8.1.130.0040.00417.70
8.1.120.0000.00717.55
8.1.110.0000.00717.52
8.1.100.0040.00417.50
8.1.90.0040.00717.53
8.1.80.0000.00817.48
8.1.70.0030.00317.50
8.1.60.0040.00417.66
8.1.50.0030.00517.55
8.1.40.0040.00417.52
8.1.30.0000.00817.61
8.1.20.0040.00417.55
8.1.10.0080.00017.65
8.1.00.0050.00317.58
8.0.300.0060.00318.77
8.0.290.0040.00416.75
8.0.280.0000.00718.49
8.0.270.0000.00817.26
8.0.260.0000.00617.29
8.0.250.0030.00317.05
8.0.240.0040.00417.02
8.0.230.0030.00316.90
8.0.220.0030.00317.02
8.0.210.0000.00716.90
8.0.200.0000.00616.92
8.0.190.0040.00416.93
8.0.180.0060.00316.90
8.0.170.0000.00816.91
8.0.160.0000.00716.92
8.0.150.0030.00616.78
8.0.140.0080.00016.87
8.0.130.0030.00313.50
8.0.120.0040.00417.05
8.0.110.0000.00816.99
8.0.100.0000.00816.92
8.0.90.0070.00016.93
8.0.80.0130.00316.97
8.0.70.0040.00416.85
8.0.60.0000.00817.09
8.0.50.0000.00716.94
8.0.30.0150.00417.16
8.0.20.0070.01417.40
8.0.10.0000.00717.18
8.0.00.0070.01116.71
7.4.330.0000.00516.86
7.4.320.0000.00716.50
7.4.300.0030.00316.66
7.4.290.0070.00016.59
7.4.280.0030.00616.67
7.4.270.0000.00716.55
7.4.260.0030.00316.45
7.4.250.0000.00816.61
7.4.240.0020.00516.58
7.4.230.0000.00716.74
7.4.220.0120.00616.47
7.4.210.0080.00816.64
7.4.200.0000.00716.66
7.4.160.0070.01916.59
7.4.150.0070.01017.40
7.4.140.0090.01417.86
7.4.130.0120.00516.66
7.4.120.0080.01216.55
7.4.110.0120.00616.46
7.4.100.0140.00316.66
7.4.90.0070.01816.57
7.4.80.0200.00319.39
7.4.70.0160.00316.55
7.4.60.0090.00916.50
7.4.50.0050.00716.68
7.4.40.0110.00716.57
7.4.30.0090.00816.46
7.4.00.0060.00615.00
7.3.330.0000.00613.44
7.3.320.0050.00013.43
7.3.310.0000.00716.46
7.3.300.0070.00016.38
7.3.290.0070.00016.35
7.3.280.0080.00916.47
7.3.270.0060.01117.40
7.3.260.0150.00316.74
7.3.250.0070.01316.57
7.3.240.0080.00816.56
7.3.230.0140.00316.62
7.3.210.0060.01216.58
7.3.200.0160.00016.54
7.3.190.0100.00616.57
7.3.180.0060.00916.64
7.3.170.0110.01016.54
7.3.160.0060.00916.55
7.3.120.0070.01314.81
7.3.110.0070.01115.08
7.3.100.0060.00915.08
7.3.90.0070.00715.11
7.3.80.0030.01015.05
7.3.70.0000.01415.04
7.3.60.0130.00314.78
7.3.50.0100.00614.97
7.3.40.0000.01114.69
7.3.30.0040.00814.90
7.3.20.0100.00316.75
7.3.10.0070.00916.71
7.3.00.0050.01016.78
7.2.330.0180.00716.89
7.2.320.0100.01016.63
7.2.310.0140.00316.83
7.2.300.0040.01616.84
7.2.290.0030.01416.72
7.2.240.0100.01015.32
7.2.230.0090.00614.64
7.2.220.0150.00015.21
7.2.210.0030.01215.29
7.2.200.0050.00515.18
7.2.190.0080.00815.08
7.2.180.0040.01515.23
7.2.170.0060.00914.92
7.2.160.0060.00615.18
7.2.150.0100.00316.76
7.2.140.0040.00817.00
7.2.130.0070.00616.96
7.2.120.0070.00417.01
7.2.110.0070.00717.07
7.2.100.0050.00816.76
7.2.90.0020.01217.04
7.2.80.0040.01217.04
7.2.70.0080.00417.03
7.2.60.0060.00816.86
7.2.50.0040.01217.11
7.2.40.0070.00817.04
7.2.30.0030.01216.82
7.2.20.0070.00616.82
7.2.10.0050.00816.89
7.2.00.0040.00917.72
7.1.330.0100.00715.77
7.1.320.0090.00915.76
7.1.310.0090.00615.98
7.1.300.0070.01015.88
7.1.290.0030.00715.57
7.1.280.0090.00315.86
7.1.270.0040.01115.86
7.1.260.0090.00615.86
7.1.250.0060.00615.82
7.1.200.0170.00315.73
7.1.100.0070.00418.10
7.1.70.0040.00417.30
7.1.60.0130.00719.13
7.1.50.0040.01416.98
7.1.00.0030.07722.33
7.0.200.0030.00616.84
7.0.60.0070.08720.06
7.0.50.0070.04317.91
7.0.40.0130.03720.40
7.0.30.0200.04020.23
7.0.20.0270.05720.20
7.0.10.0070.05020.15
7.0.00.0100.08720.07
5.6.280.0030.03321.17
5.6.210.0100.03320.76
5.6.200.0130.08018.27
5.6.190.0030.04720.47
5.6.180.0300.05020.64
5.6.170.0300.04720.56
5.6.160.0130.07720.54
5.6.150.0070.08018.21
5.6.140.0100.07718.29
5.6.130.0070.04718.30
5.6.120.0200.07021.00
5.6.110.0100.08721.08
5.6.100.0030.08320.90
5.6.90.0130.07320.98
5.6.80.0100.07020.39
5.5.350.4300.04320.36
5.5.340.0030.04317.96
5.5.330.0030.08020.25
5.5.320.0170.05320.38
5.5.310.0130.04320.24
5.5.300.0030.05018.00
5.5.290.0030.08317.98
5.5.280.0070.05020.78
5.5.270.0030.05320.78
5.5.260.0000.09320.88
5.5.250.0070.03720.78
5.5.240.0100.03020.17

preferences:
47.91 ms | 400 KiB | 5 Q