3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CategoryTree { public $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); } } 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')); echo "\n". $c->categoryExists($c->roots, 'C');

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.0120.00916.48
8.3.50.0120.00822.12
8.3.40.0090.00618.67
8.3.30.0000.01418.52
8.3.20.0070.00020.38
8.3.10.0040.00423.53
8.3.00.0120.00619.98
8.2.180.0120.00316.60
8.2.170.0040.01122.96
8.2.160.0130.00720.35
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0030.00621.00
8.2.120.0080.00026.35
8.2.110.0030.00620.35
8.2.100.0080.00417.93
8.2.90.0000.00819.17
8.2.80.0040.00417.97
8.2.70.0040.00417.50
8.2.60.0030.00618.16
8.2.50.0030.00618.07
8.2.40.0030.00620.87
8.2.30.0040.00420.68
8.2.20.0000.00717.83
8.2.10.0000.00718.13
8.2.00.0020.00518.29
8.1.280.0040.01125.92
8.1.270.0070.00320.45
8.1.260.0000.00828.09
8.1.250.0000.00928.09
8.1.240.0030.00624.02
8.1.230.0040.00717.82
8.1.220.0000.00817.79
8.1.210.0030.00518.77
8.1.200.0030.00617.35
8.1.190.0030.00617.38
8.1.180.0000.00718.10
8.1.170.0060.00318.59
8.1.160.0040.00420.82
8.1.150.0000.00718.81
8.1.140.0030.00619.57
8.1.130.0000.00717.76
8.1.120.0040.00417.52
8.1.110.0040.00417.55
8.1.100.0000.00817.45
8.1.90.0030.00517.55
8.1.80.0030.00517.50
8.1.70.0030.00317.40
8.1.60.0030.00517.56
8.1.50.0040.00417.55
8.1.40.0030.00617.54
8.1.30.0040.00417.67
8.1.20.0030.00617.65
8.1.10.0040.00417.54
8.1.00.0000.00817.58
8.0.300.0050.00318.77
8.0.290.0000.00916.88
8.0.280.0000.00718.48
8.0.270.0070.00017.35
8.0.260.0000.00617.38
8.0.250.0030.00516.98
8.0.240.0000.00617.00
8.0.230.0000.00717.02
8.0.220.0040.00416.84
8.0.210.0040.00416.95
8.0.200.0000.00617.00
8.0.190.0080.00016.90
8.0.180.0080.00316.95
8.0.170.0040.00416.88
8.0.160.0030.00317.00
8.0.150.0030.00616.87
8.0.140.0070.00416.89
8.0.130.0030.00313.38
8.0.120.0040.00416.89
8.0.110.0040.00416.92
8.0.100.0040.00417.00
8.0.90.0000.00716.77
8.0.80.0100.01016.99
8.0.70.0040.00416.92
8.0.60.0040.00416.79
8.0.50.0000.00716.88
8.0.30.0090.01117.22
8.0.20.0110.00717.43
8.0.10.0000.00716.87
8.0.00.0090.01016.96
7.4.330.0020.00216.72
7.4.320.0030.00316.57
7.4.300.0060.00016.66
7.4.290.0030.00516.58
7.4.280.0040.00416.54
7.4.270.0030.00316.49
7.4.260.0070.00016.55
7.4.250.0040.00416.52
7.4.240.0020.00516.66
7.4.230.0000.00716.56
7.4.220.0090.01216.66
7.4.210.0060.00916.54
7.4.200.0040.00416.66
7.4.160.0030.01216.58
7.4.150.0130.01017.40
7.4.140.0120.01017.86
7.4.130.0120.00516.61
7.4.120.0050.01516.50
7.4.110.0110.00716.71
7.4.100.0090.01516.63
7.4.90.0030.01516.66
7.4.80.0110.00619.39
7.4.70.0030.01316.32
7.4.60.0060.01016.48
7.4.50.0100.00316.45
7.4.40.0090.00616.47
7.4.30.0070.01416.63
7.4.00.0040.01215.19
7.3.330.0060.00013.34
7.3.320.0030.00313.43
7.3.310.0000.00716.48
7.3.300.0030.00316.29
7.3.290.0030.01116.43
7.3.280.0070.00916.42
7.3.270.0130.00317.40
7.3.260.0100.00716.38
7.3.250.0090.01216.39
7.3.240.0100.00916.50
7.3.230.0100.00716.52
7.3.210.0140.00316.64
7.3.200.0100.00716.61
7.3.190.0070.01016.48
7.3.180.0060.01016.41
7.3.170.0080.00816.52
7.3.160.0120.00916.34
7.3.10.0140.01115.93
7.3.00.0130.00516.75
7.2.330.0030.01516.71
7.2.320.0090.00916.68
7.2.310.0000.01616.45
7.2.300.0090.00916.84
7.2.290.0070.01116.80
7.2.130.0100.00716.78
7.2.120.0070.01016.64
7.2.110.0040.01416.48
7.2.100.0110.00616.80
7.2.90.0090.01116.54
7.2.80.0110.00316.57
7.2.70.0050.01416.68
7.2.60.0070.00916.86
7.2.50.0120.00616.59
7.2.40.0080.01316.53
7.2.30.0100.01116.52
7.2.20.0120.00416.65
7.2.10.0100.00916.70
7.2.00.0070.01117.74
7.1.250.0110.00315.81
7.1.240.0030.01216.02
7.1.230.0030.00715.52
7.1.220.0070.00315.71
7.1.210.0030.01015.62
7.1.200.0130.00615.79
7.1.190.0040.01115.61
7.1.180.0030.00615.52
7.1.170.0030.01015.42
7.1.160.0100.00015.72
7.1.150.0030.01415.87
7.1.140.0030.01315.72
7.1.130.0100.00715.61
7.1.120.0000.00915.60
7.1.110.0070.00716.84
7.1.100.0070.00917.30
7.1.90.0080.00716.82
7.1.80.0060.00816.95
7.1.70.0070.00516.61
7.1.60.0090.01323.28
7.1.50.0110.01022.66
7.1.40.0150.00725.09
7.1.30.0110.00925.20
7.1.20.0120.00825.01
7.1.10.0050.00916.30
7.1.00.0070.02918.34
7.0.330.0050.00315.51
7.0.320.0050.00615.18
7.0.310.0030.00715.44
7.0.300.0030.00815.35
7.0.290.0050.00515.30
7.0.280.0030.00915.28
7.0.270.0070.00415.34
7.0.260.0100.00315.21
7.0.250.0020.00816.64
7.0.240.0030.00816.74
7.0.230.0060.00516.79
7.0.220.0080.00516.53
7.0.210.0030.00815.94
7.0.200.0090.00216.31
7.0.190.0080.00515.89
7.0.180.0050.00915.60
7.0.170.0060.00815.72
7.0.160.0030.01015.81
7.0.150.0030.00915.90
7.0.140.0030.01015.83
7.0.130.0050.00816.01
7.0.120.0070.00715.92
7.0.110.0020.01216.06
7.0.100.0050.00815.92
7.0.90.0080.00515.76
7.0.80.0050.00815.73
7.0.70.0060.00615.84
7.0.60.0040.02717.25
7.0.50.0070.02016.68
7.0.40.0040.03516.77
7.0.30.0120.01916.77
7.0.20.0140.02416.64
7.0.10.0060.02016.54
7.0.00.0080.03116.61
5.6.380.0120.00314.61
5.6.370.0000.01214.51
5.6.360.0070.00714.71
5.6.350.0000.01314.61
5.6.340.0070.00714.71
5.6.330.0060.00914.80
5.6.320.0060.00914.44
5.6.310.0120.00314.70
5.6.300.0100.02817.57
5.6.290.0080.03017.55
5.6.280.0060.03418.72
5.6.270.0100.03017.72
5.6.260.0090.02917.63
5.6.250.0090.02817.52
5.6.240.0070.03917.53
5.6.230.0110.02917.52
5.6.220.0080.03117.59
5.6.210.0100.04818.50
5.6.200.0090.03917.76
5.6.190.0070.04918.54
5.6.180.0100.03918.62
5.6.170.0110.03618.45
5.6.160.0090.04718.60
5.6.150.0070.03417.77
5.6.140.0090.03217.90
5.6.130.0060.04217.81
5.6.120.0120.04818.79
5.6.110.0120.04818.79
5.6.100.0080.04018.81
5.6.90.0100.04618.66
5.6.80.0100.04518.30
5.6.70.0050.03317.14
5.6.60.0070.03317.35
5.6.50.0060.03117.38
5.6.40.0120.02817.26
5.6.30.0050.03217.20
5.6.20.0070.02917.22
5.6.10.0070.03117.19
5.6.00.0060.03117.08
5.5.380.0140.02314.51
5.5.370.0080.02814.35
5.5.360.0050.03414.15
5.5.350.0100.04416.33
5.5.340.0030.03715.78
5.5.330.0120.04316.48
5.5.320.0200.04116.47
5.5.310.0070.03716.57
5.5.300.0100.03615.75
5.5.290.0050.04615.70
5.5.280.0030.03816.61
5.5.270.0040.05116.65
5.5.260.0060.05116.70
5.5.250.0040.04116.55
5.5.240.0090.03216.35
5.5.230.0070.03014.21
5.5.220.0130.02314.17
5.5.210.0080.03214.26
5.5.200.0060.03514.13
5.5.190.0080.02914.22
5.5.180.0120.03714.21
5.5.170.0030.00311.46
5.5.160.0090.02514.23
5.5.150.0070.03814.31
5.5.140.0080.02914.32
5.5.130.0090.03114.35
5.5.120.0080.02814.18
5.5.110.0020.03514.39
5.5.100.0080.02914.33
5.5.90.0080.02514.32
5.5.80.0060.02814.08
5.5.70.0090.02714.09
5.5.60.0100.02613.88
5.5.50.0030.03114.19
5.5.40.0090.02514.15
5.5.30.0050.03213.98
5.5.20.0050.03014.22
5.5.10.0060.02713.99
5.5.00.0060.03114.28
5.4.450.0260.04316.82
5.4.440.0300.04016.65
5.4.430.0270.04216.63
5.4.420.0150.04516.70
5.4.410.0270.03416.57
5.4.400.0270.03216.45
5.4.390.0090.03616.47
5.4.380.0250.03416.37
5.4.370.0210.03816.44
5.4.360.0210.03916.28
5.4.350.0290.04316.40
5.4.340.0080.04016.31
5.4.330.0100.00311.26
5.4.320.0240.04316.48
5.4.310.0250.04016.30
5.4.300.0250.03416.46
5.4.290.0240.03816.38
5.4.280.0260.03516.33
5.4.270.0250.03216.30
5.4.260.0230.03716.44
5.4.250.0290.03116.38
5.4.240.0050.03916.27
5.4.230.0160.03916.24
5.4.220.0300.03716.35
5.4.210.0360.03416.41
5.4.200.0230.03616.45
5.4.190.0060.03916.36
5.4.180.0270.03916.35
5.4.170.0260.03716.28
5.4.160.0290.04116.30
5.4.150.0250.03816.36
5.4.140.0230.04014.69
5.4.130.0310.03214.62
5.4.120.0270.03314.63
5.4.110.0300.03614.66
5.4.100.0240.03414.76
5.4.90.0100.03213.66
5.4.80.0050.02813.61
5.4.70.0070.02713.92
5.4.60.0070.02513.77
5.4.50.0050.02813.76
5.4.40.0090.02413.94
5.4.30.0090.02513.72
5.4.20.0080.02213.61
5.4.10.0070.02913.97
5.4.00.0080.02413.58
5.3.290.0300.03713.27
5.3.280.0300.03413.05
5.3.270.0310.03713.20
5.3.260.0350.03813.21
5.3.250.0240.03613.21
5.3.240.0280.03713.18
5.3.230.0240.03813.15
5.3.220.0250.03713.13
5.3.210.0300.03313.18
5.3.200.0260.03413.08
5.3.190.0080.03612.42
5.3.180.0140.01812.63
5.3.170.0050.02612.38
5.3.160.0080.02212.49
5.3.150.0050.02712.48
5.3.140.0050.02512.34
5.3.130.0050.03112.62
5.3.120.0070.02912.45
5.3.110.0050.02712.34
5.3.100.0070.02412.27
5.3.90.0030.02912.35
5.3.80.0110.02312.18
5.3.70.0090.02412.13
5.3.60.0020.03112.38
5.3.50.0020.03112.14
5.3.40.0080.02412.19
5.3.30.0050.02612.16
5.3.20.0110.02111.88
5.3.10.0040.02411.94
5.3.00.0050.02811.98
5.2.170.0030.02510.65
5.2.160.0070.02410.67
5.2.150.0030.03210.48
5.2.140.0060.02610.58
5.2.130.0010.02710.66
5.2.120.0060.01910.61
5.2.110.0060.02110.52
5.2.100.0070.01910.62
5.2.90.0130.01410.62
5.2.80.0070.02210.51
5.2.70.0050.02610.66
5.2.60.0060.02310.64
5.2.50.0030.02310.62
5.2.40.0090.02010.56
5.2.30.0080.01910.48
5.2.20.0050.02210.58
5.2.10.0090.01610.51
5.2.00.0040.02210.40
5.1.60.0040.01910.11
5.1.50.0000.02410.12
5.1.40.0070.01610.07
5.1.30.0040.02010.27
5.1.20.0020.02210.29
5.1.10.0070.01810.05
5.1.00.0060.01810.10
5.0.50.0000.0189.27
5.0.40.0050.0139.33
5.0.30.0030.0239.15
5.0.20.0050.0139.22
5.0.10.0050.0159.16
5.0.00.0020.0229.16
4.4.90.0030.0168.26
4.4.80.0050.0118.26
4.4.70.0020.0138.26
4.4.60.0000.0148.26
4.4.50.0050.0128.26
4.4.40.0020.0208.26
4.4.30.0000.0158.26
4.4.20.0000.0168.26
4.4.10.0060.0128.26
4.4.00.0030.0178.26
4.3.110.0020.0138.26
4.3.100.0010.0138.26
4.3.90.0010.0138.26
4.3.80.0040.0218.26
4.3.70.0030.0118.26
4.3.60.0020.0128.26
4.3.50.0000.0158.26
4.3.40.0000.0228.26
4.3.30.0030.0128.26
4.3.20.0060.0098.26
4.3.10.0030.0158.26
4.3.00.0030.0128.26

preferences:
37.97 ms | 401 KiB | 5 Q