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($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.4.20.0160.00317.84
8.4.10.0030.00617.74
8.3.150.0040.01117.46
8.3.140.0090.00016.79
8.3.130.0080.00816.81
8.3.120.0160.00019.07
8.3.110.0100.01020.94
8.3.100.0070.00724.06
8.3.90.0030.00526.77
8.3.80.0110.00018.55
8.3.70.0070.00718.15
8.3.60.0070.00716.74
8.3.50.0130.00822.11
8.3.40.0070.00718.96
8.3.30.0130.00318.84
8.3.20.0000.00720.29
8.3.10.0040.00421.91
8.3.00.0000.00820.10
8.2.270.0090.00917.25
8.2.260.0050.00518.40
8.2.250.0030.00618.44
8.2.240.0100.00718.79
8.2.230.0000.00922.58
8.2.220.0100.00037.54
8.2.210.0030.00626.77
8.2.200.0040.00718.31
8.2.190.0070.00716.58
8.2.180.0170.00316.88
8.2.170.0090.00619.13
8.2.160.0120.00320.34
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0000.00819.76
8.2.110.0070.01022.29
8.2.100.0170.00018.03
8.2.90.0040.00419.40
8.2.80.0040.00417.97
8.2.70.0040.00417.61
8.2.60.0060.00317.93
8.2.50.0000.01218.07
8.2.40.0030.00518.25
8.2.30.0000.00718.11
8.2.20.0040.00417.87
8.2.10.0040.00418.23
8.2.00.0000.00718.05
8.1.310.0110.00717.00
8.1.300.0030.00617.92
8.1.290.0060.00318.88
8.1.280.0100.01425.92
8.1.270.0030.00520.73
8.1.260.0000.00826.35
8.1.250.0070.00028.09
8.1.240.0060.00320.93
8.1.230.0060.00619.54
8.1.220.0150.00318.09
8.1.210.0000.00818.77
8.1.200.0090.00417.48
8.1.190.0040.00417.60
8.1.180.0030.00618.10
8.1.170.0070.00318.63
8.1.160.0040.00418.87
8.1.150.0040.00418.95
8.1.140.0000.00919.63
8.1.130.0040.00417.76
8.1.120.0040.00417.47
8.1.110.0000.00717.42
8.1.100.0000.00817.52
8.1.90.0020.00517.54
8.1.80.0040.00417.54
8.1.70.0070.00017.55
8.1.60.0050.00317.63
8.1.50.0030.00517.51
8.1.40.0030.00617.55
8.1.30.0050.00317.59
8.1.20.0070.00017.72
8.1.10.0060.00317.57
8.1.00.0030.00717.55
8.0.300.0080.00318.77
8.0.290.0080.00017.00
8.0.280.0030.00318.51
8.0.270.0070.00017.28
8.0.260.0000.00617.25
8.0.250.0000.00717.02
8.0.240.0030.00516.96
8.0.230.0040.00417.06
8.0.220.0050.00316.98
8.0.210.0000.00817.03
8.0.200.0030.00317.09
8.0.190.0000.00817.12
8.0.180.0040.00417.02
8.0.170.0000.00817.05
8.0.160.0050.00216.95
8.0.150.0050.00316.88
8.0.140.0000.00716.96
8.0.130.0060.00615.20
8.0.120.0030.00715.71
8.0.110.0070.00515.78
8.0.100.0110.00215.81
8.0.90.0070.00615.77
8.0.80.0100.00815.82
8.0.70.0090.00415.77
8.0.60.0050.00815.74
8.0.50.0090.00415.72
8.0.30.0100.00516.25
8.0.20.0130.00616.56
8.0.10.0130.00515.92
8.0.00.0070.00816.44
7.4.330.0020.00216.71
7.4.320.0030.00316.52
7.4.300.0070.00016.65
7.4.290.0070.00016.56
7.4.280.0040.00416.45
7.4.270.0000.00716.50
7.4.260.0120.00416.64
7.4.250.0130.00215.46
7.4.240.0080.00515.73
7.4.230.0100.00415.48
7.4.220.0100.00915.47
7.4.210.0090.00815.49
7.4.200.0090.00415.40
7.4.190.0130.00415.06
7.4.180.0140.00315.02
7.4.160.0120.00514.98
7.4.150.0080.00815.83
7.4.140.0150.00916.40
7.4.130.0100.00615.86
7.4.120.0090.00715.93
7.4.110.0090.00915.58
7.4.100.0090.00915.68
7.4.90.0080.01115.78
7.4.80.0070.01316.36
7.4.70.0090.00715.71
7.4.60.0100.00615.77
7.4.50.0100.00715.71
7.4.40.0120.00515.68
7.4.30.0110.00615.77
7.4.20.0120.00715.77
7.4.10.0100.00815.72
7.4.00.0090.00915.59
7.3.330.0120.00614.62
7.3.320.0050.00614.26
7.3.310.0070.00415.25
7.3.300.0060.00615.27
7.3.290.0070.00715.91
7.3.280.0060.00915.77
7.3.270.0090.00815.88
7.3.260.0130.00415.69
7.3.250.0110.00915.96
7.3.240.0100.00615.80
7.3.230.0120.00415.60
7.3.220.0130.00615.34
7.3.210.0080.01015.50
7.3.200.0140.00516.36
7.3.190.0100.00615.70
7.3.180.0090.00815.82
7.3.170.0070.01015.84
7.3.160.0110.00415.76
7.3.150.0080.00915.85
7.3.140.0130.00615.71
7.3.130.0100.00815.83
7.3.120.0110.00815.67
7.3.110.0100.00715.61
7.3.100.0080.00915.53
7.3.90.0100.00615.72
7.3.80.0080.00815.71
7.3.70.0100.00715.61
7.3.60.0100.00615.62
7.3.50.0110.00715.61
7.3.40.0090.00715.62
7.3.30.0080.00915.56
7.3.20.0070.00816.80
7.3.10.0130.00816.52
7.3.00.0130.00716.56
7.2.340.0160.00915.46
7.2.330.0120.01115.75
7.2.320.0140.00915.97
7.2.310.0110.01015.99
7.2.300.0160.00515.96
7.2.290.0150.00616.04
7.2.280.0160.00415.86
7.2.270.0140.00615.97
7.2.260.0140.01015.98
7.2.250.0110.01015.75
7.2.240.0120.00815.83
7.2.230.0110.01015.82
7.2.220.0110.00815.87
7.2.210.0100.00815.86
7.2.200.0100.00815.92
7.2.190.0100.00815.84
7.2.180.0100.00815.85
7.2.170.0110.00615.93
7.2.160.0130.00616.00
7.2.150.0130.00617.07
7.2.140.0130.00717.01
7.2.130.0180.00616.79
7.2.120.0170.00716.81
7.2.110.0170.00916.83
7.2.100.0130.00916.77
7.2.90.0150.00816.86
7.2.80.0170.00616.49
7.2.70.0210.00716.57
7.2.60.0210.00516.64
7.2.50.0210.00716.59
7.2.40.0220.00816.57
7.2.30.0170.00916.68
7.2.20.0200.00716.58
7.2.10.0170.00616.62
7.2.00.0220.00616.62
7.1.330.0120.00915.93
7.1.320.0140.00515.94
7.1.310.0110.00815.98
7.1.300.0150.00615.91
7.1.290.0120.00715.98
7.1.280.0130.00615.84
7.1.270.0120.00815.98
7.1.260.0140.00715.89
7.1.250.0200.00615.63
7.1.240.0190.00815.64
7.1.230.0180.00815.70
7.1.220.0160.00815.68
7.1.210.0200.00415.67
7.1.200.0170.00715.67
7.1.190.0210.00715.47
7.1.180.0210.00615.44
7.1.170.0220.00715.46
7.1.160.0220.00815.42
7.1.150.0200.00715.42
7.1.140.0190.00715.45
7.1.130.0190.00715.43
7.1.120.0280.00715.47
7.1.110.0190.00715.48
7.1.100.0180.00915.52
7.1.90.0240.00615.40
7.1.80.0180.00815.49
7.1.70.0200.00615.63
7.1.60.0200.00917.68
7.1.50.0230.00817.38
7.1.40.0230.00817.50
7.1.30.0290.00817.47
7.1.20.0180.00817.42
7.1.10.0230.01015.49
7.1.00.0170.01416.11
7.0.330.0170.00814.99
7.0.320.0230.00415.12
7.0.310.0240.00614.86
7.0.300.0390.00414.82
7.0.290.0260.00714.91
7.0.280.0300.00315.17
7.0.270.0240.00714.77
7.0.260.0240.00814.80
7.0.250.0240.00914.92
7.0.240.0230.00714.94
7.0.230.0230.00714.91
7.0.220.0270.00714.79
7.0.210.0260.00714.89
7.0.200.0220.00615.10
7.0.190.0290.00714.90
7.0.180.0250.00414.86
7.0.170.0250.00814.91
7.0.160.0260.00814.85
7.0.150.0300.00814.90
7.0.140.0310.00914.82
7.0.130.0250.00914.87
7.0.120.0250.00614.89
7.0.110.0260.00714.88
7.0.100.0280.00914.83
7.0.90.0290.00714.87
7.0.80.0240.00514.77
7.0.70.0260.00614.81
7.0.60.0260.01215.53
7.0.50.0240.01415.26
7.0.40.0200.01815.51
7.0.30.0240.01615.54
7.0.20.0220.01315.49
7.0.10.0230.01715.53
7.0.00.0170.01615.53
5.6.400.0170.00815.39
5.6.390.0140.00915.42
5.6.380.0130.00815.31
5.6.370.0160.00915.15
5.6.360.0180.00615.29
5.6.350.0140.00715.31
5.6.340.0140.00815.32
5.6.330.0160.00815.20
5.6.320.0160.00815.27
5.6.310.0150.00815.18
5.6.300.0180.01214.93
5.6.290.0160.00815.08
5.6.280.0130.01215.76
5.6.270.0150.00915.19
5.6.260.0150.00815.10
5.6.250.0120.01115.12
5.6.240.0160.00915.19
5.6.230.0120.01215.10
5.6.220.0170.00715.10
5.6.210.0140.01615.78
5.6.200.0120.02015.57
5.6.190.0150.01515.87
5.6.180.0160.01615.78
5.6.170.0160.01215.75
5.6.160.0130.01415.86
5.6.150.0170.01615.52
5.6.140.0140.01515.47
5.6.130.0130.01315.51
5.6.120.0150.01215.89
5.6.110.0120.01515.80
5.6.100.0130.01815.92
5.6.90.0150.01615.86
5.6.80.0090.01915.74
5.6.70.0100.01215.07
5.6.60.0130.01015.07
5.6.50.0140.00914.97
5.6.40.0100.01015.01
5.6.30.0130.00815.05
5.6.20.0120.00915.07
5.6.10.0130.00714.98
5.6.00.0130.01015.00
5.5.380.0110.00914.27
5.5.370.0150.00614.28
5.5.360.0150.00914.20
5.5.350.0160.01614.87
5.5.340.0130.01714.71
5.5.330.0160.01614.92
5.5.320.0140.01614.93
5.5.310.0140.01014.83
5.5.300.0160.01514.66
5.5.290.0140.01314.63
5.5.280.0120.01214.97
5.5.270.0140.01514.96
5.5.260.0130.01514.97
5.5.250.0110.01214.93
5.5.240.0150.01414.87
5.5.230.0140.00814.02
5.5.220.0190.00714.06
5.5.210.0150.00614.17
5.5.200.0140.00714.01
5.5.190.0100.00914.10
5.5.180.0120.00914.10
5.5.170.0160.00614.57
5.5.160.0140.00914.09
5.5.150.0150.00614.04
5.5.140.0140.00714.01
5.5.130.0130.00813.96
5.5.120.0110.01114.03
5.5.110.0120.00814.05
5.5.100.0130.00714.21
5.5.90.0120.00914.13
5.5.80.0120.00814.18
5.5.70.0150.00614.21
5.5.60.0140.00714.10
5.5.50.0130.00814.09
5.5.40.0120.00914.11
5.5.30.0120.00814.13
5.5.20.0150.00614.24
5.5.10.0120.00814.06
5.5.00.0140.00714.09

preferences:
134.98 ms | 403 KiB | 5 Q