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(); } 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(); } 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) { $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.0040.01116.75
8.3.50.0170.00221.99
8.3.40.0070.01118.94
8.3.30.0090.00618.87
8.3.20.0040.00420.16
8.3.10.0070.00021.90
8.3.00.0040.00419.97
8.2.180.0000.01518.54
8.2.170.0070.01122.96
8.2.160.0060.00919.50
8.2.150.0030.00524.18
8.2.140.0080.00024.66
8.2.130.0050.00321.06
8.2.120.0040.00426.35
8.2.110.0070.00321.18
8.2.100.0040.00818.03
8.2.90.0040.00418.16
8.2.80.0060.00318.16
8.2.70.0100.00017.75
8.2.60.0080.00017.75
8.2.50.0040.00417.75
8.2.40.0060.00319.48
8.2.30.0040.00420.59
8.2.20.0030.00517.87
8.2.10.0040.00418.20
8.2.00.0000.00718.13
8.1.280.0110.00425.92
8.1.270.0030.00523.99
8.1.260.0070.00028.09
8.1.250.0040.00428.09
8.1.240.0030.00622.46
8.1.230.0070.00720.88
8.1.220.0000.00917.74
8.1.210.0030.00518.77
8.1.200.0000.00817.35
8.1.190.0040.00717.48
8.1.180.0000.00818.10
8.1.170.0030.00619.09
8.1.160.0080.00020.93
8.1.150.0000.00718.88
8.1.140.0090.00019.55
8.1.130.0000.00717.67
8.1.120.0050.00217.51
8.1.110.0040.00417.50
8.1.100.0000.00717.53
8.1.90.0000.00717.50
8.1.80.0050.00317.53
8.1.70.0000.00817.45
8.1.60.0040.00417.61
8.1.50.0040.00417.46
8.1.40.0090.00017.47
8.1.30.0080.00017.75
8.1.20.0040.00417.71
8.1.10.0080.00017.66
8.1.00.0000.00917.50
8.0.300.0040.00420.01
8.0.290.0000.00816.75
8.0.280.0030.00318.41
8.0.270.0080.00017.31
8.0.260.0000.00617.36
8.0.250.0000.00717.07
8.0.240.0060.00317.04
8.0.230.0030.00617.04
8.0.220.0000.00716.99
8.0.210.0000.00716.94
8.0.200.0040.00416.98
8.0.190.0040.00417.04
8.0.180.0040.00416.94
8.0.170.0000.00817.02
8.0.160.0030.00417.04
8.0.150.0030.00717.08
8.0.140.0060.00316.93
8.0.130.0000.00613.42
8.0.120.0040.00417.05
8.0.110.0040.00416.93
8.0.100.0050.00316.86
8.0.90.0070.00016.94
8.0.80.0100.00616.97
8.0.70.0040.00416.88
8.0.60.0040.00416.89
8.0.50.0000.00716.96
8.0.30.0080.00717.30
8.0.20.0130.00617.41
8.0.10.0000.00816.96
8.0.00.0090.01116.88
7.4.330.0020.00216.81
7.4.320.0030.00316.57
7.4.300.0000.00716.57
7.4.290.0000.00716.55
7.4.280.0080.00016.64
7.4.270.0000.00816.63
7.4.260.0000.00816.61
7.4.250.0040.00416.42
7.4.240.0040.00416.65
7.4.230.0030.00316.54
7.4.220.0130.00316.71
7.4.210.0100.00516.60
7.4.200.0050.00316.66
7.4.160.0080.00816.40
7.4.150.0080.00817.40
7.4.140.0130.00917.86
7.4.130.0100.00816.65
7.4.120.0110.00916.73
7.4.110.0100.00716.69
7.4.100.0070.01616.55
7.4.90.0090.00916.57
7.4.80.0090.01319.39
7.4.70.0000.01916.84
7.4.60.0070.01016.80
7.4.50.0030.01316.64
7.4.40.0060.01016.50
7.4.30.0100.00716.47
7.4.10.0070.01114.88
7.4.00.0060.00414.83
7.3.330.0050.00013.53
7.3.320.0000.00513.52
7.3.310.0040.00416.50
7.3.300.0060.00316.46
7.3.290.0040.01316.48
7.3.280.0090.00816.46
7.3.270.0100.00717.40
7.3.260.0060.01216.45
7.3.250.0110.01216.59
7.3.240.0130.00316.48
7.3.230.0030.01416.56
7.3.210.0140.00316.65
7.3.200.0040.01316.46
7.3.190.0090.00916.59
7.3.180.0030.01416.68
7.3.170.0030.01416.45
7.3.160.0130.01016.70
7.3.130.0070.01114.93
7.3.120.0060.01315.00
7.3.110.0060.01114.61
7.3.100.0040.01114.93
7.3.90.0060.00914.53
7.3.80.0000.01114.80
7.3.70.0100.00314.89
7.3.60.0070.00714.95
7.3.50.0040.00815.01
7.3.40.0030.01014.75
7.3.30.0060.01214.94
7.3.20.0000.01316.53
7.3.10.0000.01316.65
7.3.00.0040.00716.66
7.2.330.0130.01316.71
7.2.320.0030.01416.92
7.2.310.0100.01016.54
7.2.300.0110.00616.88
7.2.290.0110.00716.62
7.2.260.0100.00715.00
7.2.250.0060.01215.25
7.2.240.0040.01515.02
7.2.230.0060.01315.26
7.2.220.0040.00715.26
7.2.210.0000.01515.13
7.2.200.0000.01014.86
7.2.190.0040.01115.11
7.2.180.0060.00615.11
7.2.170.0060.00914.93
7.2.160.0070.00415.21
7.2.150.0060.00916.95
7.2.140.0030.00617.12
7.2.130.0130.00316.97
7.2.120.0090.00916.97
7.2.110.0030.01316.72
7.2.100.0040.01116.98
7.2.90.0060.00916.59
7.2.80.0060.00916.68
7.2.70.0060.00617.13
7.2.60.0080.00516.89
7.2.50.0070.00716.83
7.2.40.0000.01417.00
7.2.30.0080.00816.81
7.2.20.0040.00816.94
7.2.10.0030.01317.08
7.2.00.0080.00518.00
7.1.330.0120.00315.82
7.1.320.0040.01116.02
7.1.310.0060.01015.75
7.1.300.0100.00715.59
7.1.290.0080.00415.96
7.1.280.0120.00315.97
7.1.270.0030.01515.50
7.1.260.0030.00615.48
7.1.250.0080.00415.51
7.1.240.0080.00615.85
7.1.230.0000.00915.85
7.1.220.0030.01315.79
7.1.210.0030.01015.63
7.1.200.0040.00915.74
7.1.190.0040.00915.99
7.1.180.0030.00815.86
7.1.170.0000.01215.83
7.1.160.0070.00415.77
7.1.150.0030.01015.74
7.1.140.0040.01115.96
7.1.130.0000.01415.63
7.1.120.0070.01015.55
7.1.110.0070.00415.81
7.1.100.0090.00617.13
7.1.90.0070.00715.96
7.1.80.0030.01015.80
7.1.70.0070.00616.60
7.1.60.0050.00717.39
7.1.50.0060.01316.55
7.1.40.0030.00915.70
7.1.30.0030.01215.57
7.1.20.0040.01115.94
7.1.10.0030.01015.76
7.1.00.0080.03818.95
7.0.330.0090.00615.33
7.0.320.0030.01415.26
7.0.310.0000.00815.24
7.0.300.0060.00615.45
7.0.290.0040.00815.07
7.0.280.0100.00715.41
7.0.270.0000.00915.36
7.0.260.0070.00715.25
7.0.250.0070.00715.50
7.0.240.0150.00015.30
7.0.230.0130.00315.67
7.0.220.0080.00815.56
7.0.210.0070.00715.37
7.0.200.0020.00916.09
7.0.190.0030.01015.34
7.0.180.0110.00015.45
7.0.170.0090.00415.43
7.0.160.0140.00315.32
7.0.150.0090.00615.44
7.0.140.0140.00015.39
7.0.130.0030.01015.34
7.0.120.0040.00715.21
7.0.110.0070.00715.61
7.0.100.0000.01415.57
7.0.90.0030.00915.05
7.0.80.0130.00315.43
7.0.70.0070.00715.50
7.0.60.0040.02417.67
7.0.50.0130.03816.68
7.0.40.0030.04516.74
7.0.30.0140.02916.75
7.0.20.0170.02416.89
7.0.10.0080.04116.96
7.0.00.0100.04316.80
5.6.400.0070.00714.50
5.6.390.0110.00714.60
5.6.380.0040.00814.33
5.6.370.0070.00314.14
5.6.360.0000.00914.56
5.6.350.0060.00914.81
5.6.340.0000.01514.48
5.6.330.0030.01314.55
5.6.320.0080.00613.97
5.6.310.0030.00714.34
5.6.300.0080.00814.52
5.6.290.0060.00314.38
5.6.280.0030.02817.81
5.6.270.0060.00914.49
5.6.260.0060.00914.48
5.6.250.0000.01314.44
5.6.240.0040.00814.41
5.6.230.0000.00814.27
5.6.220.0080.00814.53
5.6.210.0080.03217.37
5.6.200.0080.04016.13
5.6.190.0100.04517.64
5.6.180.0120.04717.51
5.6.170.0180.02217.45
5.6.160.0030.02417.49
5.6.150.0030.04916.14
5.6.140.0110.02616.37
5.6.130.0050.02316.32
5.6.120.0050.03217.62
5.6.110.0030.03517.63
5.6.100.0130.04017.62
5.6.90.0060.03117.70
5.6.80.0100.03717.47
5.6.70.0070.01014.24
5.6.60.0070.01114.29
5.6.50.0030.01214.71
5.6.40.0050.00514.24
5.6.30.0070.01114.09
5.6.20.0070.00314.30
5.6.10.0060.00614.38
5.6.00.0030.00514.13
5.5.380.0030.01014.48
5.5.370.0000.01214.37
5.5.360.0060.00614.70
5.5.350.0190.04117.22
5.5.340.0050.02916.27
5.5.330.0000.03117.34
5.5.320.0130.04017.15
5.5.310.0080.02817.38
5.5.300.0090.04016.20
5.5.290.0050.04716.32
5.5.280.0050.04417.54
5.5.270.0080.02817.69
5.5.260.0090.02717.49
5.5.250.0020.02917.54
5.5.240.0070.02417.30
5.5.230.0060.00314.33
5.5.220.0030.01014.38
5.5.210.0090.00314.45
5.5.200.0140.00314.28
5.5.190.0030.01013.95
5.5.180.0000.01014.60
5.5.170.0110.00014.31
5.5.160.0110.00314.26
5.5.150.0100.00314.38
5.5.140.0110.00714.38
5.5.130.0000.01514.25
5.5.120.0040.00714.23
5.5.110.0070.00714.42
5.5.100.0040.01413.92
5.5.90.0060.00314.27
5.5.80.0080.00014.22
5.5.70.0000.00914.34
5.5.60.0040.00914.04
5.5.50.0080.01114.41
5.5.40.0070.00714.51
5.5.30.0030.01314.12
5.5.20.0040.01214.52
5.5.10.0030.01014.21
5.5.00.0070.00714.59

preferences:
41.19 ms | 401 KiB | 5 Q