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($node 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.00416.50
8.3.50.0100.01021.98
8.3.40.0150.00018.84
8.3.30.0150.00018.84
8.3.20.0040.00420.27
8.3.10.0070.00023.66
8.3.00.0040.00419.85
8.2.180.0120.00318.63
8.2.170.0110.00322.96
8.2.160.0030.01019.32
8.2.150.0080.00024.18
8.2.140.0030.00524.66
8.2.130.0060.00321.01
8.2.120.0120.00326.35
8.2.110.0030.00620.53
8.2.100.0040.00818.03
8.2.90.0030.00619.27
8.2.80.0000.00817.97
8.2.70.0070.00317.75
8.2.60.0040.00818.04
8.2.50.0030.00618.07
8.2.40.0100.00021.15
8.2.30.0030.00320.54
8.2.20.0030.00617.84
8.2.10.0040.00418.22
8.2.00.0070.00018.29
8.1.280.0140.00025.92
8.1.270.0060.00318.95
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0060.00322.18
8.1.230.0080.00317.68
8.1.220.0000.00817.74
8.1.210.0050.00318.77
8.1.200.0060.00317.36
8.1.190.0060.00317.48
8.1.180.0040.00418.10
8.1.170.0050.00318.64
8.1.160.0040.00420.91
8.1.150.0000.00718.88
8.1.140.0050.00219.48
8.1.130.0070.00017.66
8.1.120.0000.00717.53
8.1.110.0030.00517.39
8.1.100.0040.00417.40
8.1.90.0070.00017.50
8.1.80.0040.00417.45
8.1.70.0040.00417.38
8.1.60.0000.00717.52
8.1.50.0040.00417.52
8.1.40.0000.00817.43
8.1.30.0040.00417.56
8.1.20.0060.00317.67
8.1.10.0040.00417.63
8.1.00.0000.00717.59
8.0.300.0040.00418.77
8.0.290.0040.00417.00
8.0.280.0070.00018.49
8.0.270.0000.00717.22
8.0.260.0040.00417.30
8.0.250.0030.00317.06
8.0.240.0060.00317.02
8.0.230.0000.00817.08
8.0.220.0020.00516.87
8.0.210.0000.00816.96
8.0.200.0000.00617.09
8.0.190.0040.00416.99
8.0.180.0030.00517.08
8.0.170.0000.00817.00
8.0.160.0040.00416.98
8.0.150.0040.00416.89
8.0.140.0040.00416.80
8.0.130.0030.00313.38
8.0.120.0040.00416.96
8.0.110.0050.00317.07
8.0.100.0020.00517.05
8.0.90.0050.00216.89
8.0.80.0050.01117.01
8.0.70.0040.00416.86
8.0.60.0040.00417.06
8.0.50.0040.00416.95
8.0.30.0110.01017.13
8.0.20.0080.01317.40
8.0.10.0030.00617.14
8.0.00.0070.01216.80
7.4.330.0020.00316.71
7.4.320.0030.00316.65
7.4.300.0030.00316.52
7.4.290.0070.00016.45
7.4.280.0050.00216.50
7.4.270.0030.00316.57
7.4.260.0050.00216.43
7.4.250.0040.00416.61
7.4.240.0020.00516.64
7.4.230.0050.00316.42
7.4.220.0090.00916.54
7.4.210.0030.01616.50
7.4.200.0040.00416.54
7.4.160.0110.00716.73
7.4.150.0100.00717.40
7.4.140.0090.01217.86
7.4.130.0100.00716.48
7.4.120.0060.01216.57
7.4.110.0120.01116.69
7.4.100.0040.01416.59
7.4.90.0090.01516.67
7.4.80.0090.00919.39
7.4.70.0140.00316.69
7.4.60.0060.01016.55
7.4.50.0030.01016.51
7.4.40.0080.00816.70
7.4.30.0090.01316.50
7.4.10.0060.01315.34
7.4.00.0040.01314.95
7.3.330.0000.00513.19
7.3.320.0000.00513.36
7.3.310.0050.00316.23
7.3.300.0070.00016.39
7.3.290.0060.01116.40
7.3.280.0070.00916.39
7.3.270.0030.01417.40
7.3.260.0100.00716.43
7.3.250.0080.00916.50
7.3.240.0100.00716.52
7.3.230.0070.01016.51
7.3.210.0100.00716.61
7.3.200.0130.00416.43
7.3.190.0060.01916.47
7.3.180.0030.01316.66
7.3.170.0040.01716.48
7.3.160.0080.00816.55
7.3.130.0000.01014.85
7.3.120.0100.00714.98
7.3.110.0100.00514.81
7.3.100.0050.01115.05
7.3.90.0070.01114.97
7.3.80.0050.00614.94
7.3.70.0030.01214.80
7.3.60.0040.01214.97
7.3.50.0060.00614.84
7.3.40.0070.00914.94
7.3.30.0040.00914.93
7.3.20.0060.00816.62
7.3.10.0080.00816.45
7.3.00.0060.00916.70
7.2.330.0140.00316.66
7.2.320.0120.00616.75
7.2.310.0070.01016.52
7.2.300.0060.01216.52
7.2.290.0060.01116.41
7.2.260.0040.01414.61
7.2.250.0110.00814.98
7.2.240.0060.01115.01
7.2.230.0050.00915.05
7.2.220.0070.00915.11
7.2.210.0030.01015.13
7.2.200.0020.01215.00
7.2.190.0040.01214.99
7.2.180.0030.00914.94
7.2.170.0020.01115.16
7.2.160.0000.01715.19
7.2.150.0070.01016.93
7.2.140.0030.01016.82
7.2.130.0060.00317.00
7.2.120.0070.00717.03
7.2.110.0000.01316.77
7.2.100.0060.00616.68
7.2.90.0030.00916.97
7.2.80.0060.00317.11
7.2.70.0090.00617.11
7.2.60.0080.00716.89
7.2.50.0070.01016.95
7.2.40.0060.00617.04
7.2.30.0090.00617.02
7.2.20.0060.00917.06
7.2.10.0030.00916.91
7.2.00.0070.00718.29
7.1.330.0060.00715.80
7.1.320.0030.01115.86
7.1.310.0090.00415.71
7.1.300.0030.00815.79
7.1.290.0060.00615.71
7.1.280.0100.00615.67
7.1.270.0050.00815.55
7.1.260.0090.00415.71
7.1.250.0060.00615.74
7.1.240.0030.01015.82
7.1.230.0040.00415.86
7.1.220.0060.00315.86
7.1.210.0070.00315.88
7.1.200.0150.00315.66
7.1.190.0100.00715.90
7.1.180.0040.00715.83
7.1.170.0080.00615.77
7.1.160.0030.01015.93
7.1.150.0040.01215.93
7.1.140.0070.00415.81
7.1.130.0000.00815.57
7.1.120.0030.00615.81
7.1.110.0080.00015.94
7.1.100.0030.01316.94
7.1.90.0100.00615.71
7.1.80.0090.00915.86
7.1.70.0040.00716.43
7.1.60.0070.01017.49
7.1.50.0050.01116.36
7.1.40.0060.00615.82
7.1.30.0090.00315.95
7.1.20.0030.01015.36
7.1.10.0030.00615.94
7.1.00.0090.03919.05
7.0.330.0060.00615.38
7.0.320.0090.00015.39
7.0.310.0060.00315.57
7.0.300.0080.00815.12
7.0.290.0070.00715.39
7.0.280.0000.01315.48
7.0.270.0100.00315.44
7.0.260.0060.00615.48
7.0.250.0000.01515.60
7.0.240.0100.00715.18
7.0.230.0070.00715.54
7.0.220.0000.01115.45
7.0.210.0070.00415.52
7.0.200.0170.00515.08
7.0.190.0030.00615.43
7.0.180.0030.00715.56
7.0.170.0000.01415.19
7.0.160.0000.00815.24
7.0.150.0070.00315.40
7.0.140.0050.00815.57
7.0.130.0000.01415.56
7.0.120.0060.01215.60
7.0.110.0040.01115.26
7.0.100.0040.00815.57
7.0.90.0080.00615.16
7.0.80.0080.00015.32
7.0.70.0030.01315.60
7.0.60.0120.02717.81
7.0.50.0050.02816.59
7.0.40.0020.02816.87
7.0.30.0190.04116.93
7.0.20.0120.02416.89
7.0.10.0050.03916.89
7.0.00.0100.04216.72
5.6.400.0000.01114.26
5.6.390.0060.00614.32
5.6.380.0030.00714.09
5.6.370.0040.00814.33
5.6.360.0060.00914.72
5.6.350.0100.00314.54
5.6.340.0040.01114.65
5.6.330.0100.00314.72
5.6.320.0000.01014.48
5.6.310.0080.00414.42
5.6.300.0130.00014.62
5.6.290.0030.00714.63
5.6.280.0030.02017.55
5.6.270.0100.00714.25
5.6.260.0030.00914.67
5.6.250.0070.01014.54
5.6.240.0080.00514.50
5.6.230.0040.00814.23
5.6.220.0090.00614.29
5.6.210.0080.02317.53
5.6.200.0100.04016.34
5.6.190.0060.02517.38
5.6.180.0120.02517.59
5.6.170.0170.02517.58
5.6.160.0050.04417.48
5.6.150.0120.03916.24
5.6.140.0000.02816.22
5.6.130.0060.04616.16
5.6.120.0030.03217.80
5.6.110.0080.04417.64
5.6.100.0080.03017.58
5.6.90.0050.04117.63
5.6.80.0090.02517.32
5.6.70.0000.01314.40
5.6.60.0090.00914.30
5.6.50.0100.01014.27
5.6.40.0090.00914.23
5.6.30.0000.01414.20
5.6.20.0030.01014.20
5.6.10.0060.00614.45
5.6.00.0040.01114.32
5.5.380.0170.00013.91
5.5.370.0100.00614.22
5.5.360.0070.00714.43
5.5.350.0150.03817.53
5.5.340.0090.02215.97
5.5.330.0070.02717.42
5.5.320.0220.04717.25
5.5.310.0140.04617.28
5.5.300.0030.02716.30
5.5.290.0080.04516.08
5.5.280.0080.02317.74
5.5.270.0050.02517.56
5.5.260.0100.04217.57
5.5.250.0100.03317.49
5.5.240.0070.04317.28
5.5.230.0030.01014.04
5.5.220.0040.01214.25
5.5.210.0070.00714.27
5.5.200.0060.01314.31
5.5.190.0060.00614.32
5.5.180.0000.01013.79
5.5.170.0040.00814.33
5.5.160.0080.00014.11
5.5.150.0120.00314.36
5.5.140.0070.01014.12
5.5.130.0060.01014.09
5.5.120.0050.00314.05
5.5.110.0000.01114.42
5.5.100.0090.00314.20
5.5.90.0000.00814.32
5.5.80.0030.01014.20
5.5.70.0040.01114.34
5.5.60.0070.00714.32
5.5.50.0060.00913.75
5.5.40.0040.01214.19
5.5.30.0030.01314.29
5.5.20.0030.01214.30
5.5.10.0060.00914.16
5.5.00.0000.01413.96

preferences:
49.29 ms | 401 KiB | 5 Q