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('test'); } if ($parent === null) { $this->roots[$category] = []; return; } var_dump($parent); $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('test2'); } 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) { echo $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.40.0110.00418.92
8.3.30.0090.00618.76
8.3.20.0070.00020.30
8.3.10.0080.00023.65
8.3.00.0080.00019.97
8.2.170.0070.00722.96
8.2.160.0100.00319.40
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0000.00921.06
8.2.120.0000.01026.35
8.2.110.0100.00020.56
8.2.100.0000.01218.05
8.2.90.0040.00419.35
8.2.80.0000.00817.97
8.2.70.0040.00817.75
8.2.60.0100.00017.68
8.2.50.0000.00918.07
8.2.40.0030.00619.39
8.2.30.0080.00020.74
8.2.20.0050.00317.99
8.2.10.0070.00018.09
8.2.00.0000.00818.04
8.1.270.0060.00320.64
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0040.00422.13
8.1.230.0000.01117.66
8.1.220.0050.00317.77
8.1.210.0000.00818.77
8.1.200.0060.00317.48
8.1.190.0050.00317.47
8.1.180.0000.00818.10
8.1.170.0030.00618.73
8.1.160.0000.00720.81
8.1.150.0070.00018.90
8.1.140.0000.00819.55
8.1.130.0000.00717.74
8.1.120.0000.00717.56
8.1.110.0040.00417.41
8.1.100.0080.00017.40
8.1.90.0070.00017.43
8.1.80.0000.00817.47
8.1.70.0050.00317.52
8.1.60.0040.00417.57
8.1.50.0040.00417.52
8.1.40.0030.00517.57
8.1.30.0050.00317.75
8.1.20.0040.00417.57
8.1.10.0080.00017.67
8.1.00.0040.00417.61
8.0.300.0060.00318.77
8.0.290.0040.00416.88
8.0.280.0070.00018.45
8.0.270.0030.00317.19
8.0.260.0060.00017.37
8.0.250.0000.00717.07
8.0.240.0050.00217.01
8.0.230.0070.00017.04
8.0.220.0000.00817.00
8.0.210.0000.00716.86
8.0.200.0040.00417.06
8.0.190.0040.00417.08
8.0.180.0000.00716.92
8.0.170.0090.00017.03
8.0.160.0080.00016.89
8.0.150.0050.00317.05
8.0.140.0050.00516.96
8.0.130.0060.00013.32
8.0.120.0080.00016.88
8.0.110.0050.00217.05
8.0.100.0000.00816.86
8.0.90.0040.00416.95
8.0.80.0060.01017.01
8.0.70.0040.00417.02
8.0.60.0070.00016.82
8.0.50.0040.00417.00
8.0.30.0070.01217.24
8.0.20.0130.00617.41
8.0.10.0030.00517.11
8.0.00.0050.01316.82
7.4.330.0050.00016.67
7.4.320.0030.00316.63
7.4.300.0000.00716.47
7.4.290.0000.00716.66
7.4.280.0000.00916.56
7.4.270.0000.00716.56
7.4.260.0030.00416.63
7.4.250.0050.00316.55
7.4.240.0050.00216.58
7.4.230.0030.00516.72
7.4.220.0100.00916.51
7.4.210.0120.00316.59
7.4.200.0000.00816.66
7.4.160.0090.00916.54
7.4.150.0100.01017.40
7.4.140.0120.01317.86
7.4.130.0080.01016.52
7.4.120.0100.01016.59
7.4.110.0100.01016.75
7.4.100.0130.00516.59
7.4.90.0140.00316.55
7.4.80.0030.01819.39
7.4.70.0070.01016.63
7.4.60.0140.00416.52
7.4.50.0070.00716.61
7.4.40.0090.00916.53
7.4.30.0070.01316.55
7.4.10.0030.01316.42
7.4.00.0090.00715.48
7.3.330.0050.00013.25
7.3.320.0000.00513.30
7.3.310.0000.00716.58
7.3.300.0070.00016.48
7.3.290.0080.00716.45
7.3.280.0110.01016.47
7.3.270.0110.00617.40
7.3.260.0110.00716.84
7.3.250.0110.00816.47
7.3.240.0070.00916.54
7.3.230.0140.00316.55
7.3.210.0100.00716.62
7.3.200.0140.00816.66
7.3.190.0140.00316.47
7.3.180.0090.01216.52
7.3.170.0160.00016.66
7.3.160.0170.00716.62
7.3.130.0100.00716.35
7.3.120.0080.00915.77
7.3.110.0050.01215.70
7.3.100.0060.00715.72
7.3.90.0060.00715.63
7.3.80.0060.00615.60
7.3.70.0070.01115.62
7.3.60.0070.00515.60
7.3.50.0100.00515.61
7.3.40.0060.00515.72
7.3.30.0080.00615.68
7.3.20.0030.01217.50
7.3.10.0110.00317.53
7.3.00.0050.00817.45
7.2.330.0090.00916.91
7.2.320.0060.01816.73
7.2.310.0190.00316.78
7.2.300.0070.01016.52
7.2.290.0100.01016.84
7.2.260.0040.01816.68
7.2.250.0100.00816.02
7.2.240.0030.01715.85
7.2.230.0060.01216.04
7.2.220.0060.00815.98
7.2.210.0050.01315.90
7.2.200.0070.01215.88
7.2.190.0070.00315.77
7.2.180.0080.00515.76
7.2.170.0070.00415.95
7.2.160.0090.00916.46
7.2.150.0080.01118.46
7.2.140.0100.00318.39
7.2.130.0070.00718.54
7.2.120.0000.01418.37
7.2.110.0100.00318.50
7.2.100.0030.00918.50
7.2.90.0030.01618.36
7.2.80.0070.00718.52
7.2.70.0070.01418.00
7.2.60.0090.00917.37
7.2.50.0060.00918.66
7.2.40.0000.01618.45
7.2.30.0060.00818.41
7.2.20.0060.00918.43
7.2.10.0080.00418.50
7.2.00.0050.01118.95
7.1.330.0020.01416.46
7.1.320.0040.01116.59
7.1.310.0060.01016.64
7.1.300.0070.00316.53
7.1.290.0030.00816.63
7.1.280.0090.00516.43
7.1.270.0080.00716.70
7.1.260.0000.00916.59
7.1.250.0060.00917.27
7.1.240.0060.00917.32
7.1.230.0060.00917.31
7.1.220.0060.00817.35
7.1.210.0060.00317.26
7.1.200.0110.00816.53
7.1.190.0030.01317.32
7.1.180.0030.01217.29
7.1.170.0070.00717.41
7.1.160.0090.00317.29
7.1.150.0030.00617.53
7.1.140.0030.01417.36
7.1.130.0030.01317.25
7.1.120.0030.00617.20
7.1.110.0030.01317.36
7.1.100.0000.01117.71
7.1.90.0070.00717.31
7.1.80.0040.01217.41
7.1.70.0080.00517.38
7.1.60.0050.00718.17
7.1.50.0050.01317.15
7.1.40.0030.01217.37
7.1.30.0070.01017.44
7.1.20.0030.01317.34
7.1.10.0040.01117.19
7.1.00.0020.04719.84
7.0.330.0070.00717.18
7.0.320.0060.00917.07
7.0.310.0050.00517.05
7.0.300.0060.00617.04
7.0.290.0110.00317.25
7.0.280.0030.00617.27
7.0.270.0080.00317.05
7.0.260.0030.01017.14
7.0.250.0040.00716.84
7.0.240.0070.00717.15
7.0.230.0090.00317.10
7.0.220.0100.00617.17
7.0.210.0030.01017.08
7.0.200.0080.00316.89
7.0.190.0060.00617.07
7.0.180.0110.00716.93
7.0.170.0100.00717.11
7.0.160.0140.00417.14
7.0.150.0030.01017.14
7.0.140.0000.01416.99
7.0.130.0040.01217.07
7.0.120.0060.01016.81
7.0.110.0070.00716.90
7.0.100.0030.01316.94
7.0.90.0030.00716.92
7.0.80.0100.00717.02
7.0.70.0070.00716.79
7.0.60.0050.02518.46
7.0.50.0050.02317.39
7.0.40.0070.04517.57
7.0.30.0100.02717.74
7.0.20.0120.03017.60
7.0.10.0060.02617.56
7.0.00.0080.02717.64
5.6.400.0030.00915.81
5.6.390.0070.00716.38
5.6.380.0000.01416.00
5.6.370.0030.01415.99
5.6.360.0030.00616.07
5.6.350.0090.00315.86
5.6.340.0040.00716.13
5.6.330.0030.00915.74
5.6.320.0090.00616.12
5.6.310.0000.01316.20
5.6.300.0070.00315.95
5.6.290.0070.01016.36
5.6.280.0090.03118.51
5.6.270.0090.00916.07
5.6.260.0000.01616.00
5.6.250.0030.00716.04
5.6.240.0130.00316.16
5.6.230.0030.01416.14
5.6.220.0000.00915.92
5.6.210.0050.04618.20
5.6.200.0050.04317.15
5.6.190.0100.04518.38
5.6.180.0120.02718.24
5.6.170.0120.02818.18
5.6.160.0040.03218.38
5.6.150.0060.02317.08
5.6.140.0060.04617.08
5.6.130.0070.04017.05
5.6.120.0100.02818.61
5.6.110.0080.04018.45
5.6.100.0040.04918.44
5.6.90.0110.02618.54
5.6.80.0080.03518.17
5.6.70.0090.00315.82
5.6.60.0030.01015.88
5.6.50.0030.01016.10
5.6.40.0030.01015.91
5.6.30.0090.00615.83
5.6.20.0000.01615.93
5.6.10.0040.01415.69
5.6.00.0080.00416.07
5.5.380.0060.01015.96
5.5.370.0000.01416.33
5.5.360.0060.00615.75
5.5.350.0210.03818.17
5.5.340.0070.04417.01
5.5.330.0030.02818.25
5.5.320.0170.04617.96
5.5.310.0130.03818.20
5.5.300.0070.04716.93
5.5.290.0040.02917.01
5.5.280.0060.04518.53
5.5.270.0080.04318.38
5.5.260.0110.02018.32
5.5.250.0120.03718.20
5.5.240.0120.03718.04
5.5.230.0080.00715.75
5.5.220.0000.00916.02
5.5.210.0080.00415.92
5.5.200.0040.01416.10
5.5.190.0000.01015.74
5.5.180.0080.00815.76
5.5.170.0120.00416.11
5.5.160.0080.00816.01
5.5.150.0040.01116.13
5.5.140.0130.00715.68
5.5.130.0120.00015.91
5.5.120.0090.00615.82
5.5.110.0060.01015.92
5.5.100.0100.00615.77
5.5.90.0070.00716.00
5.5.80.0040.01115.89
5.5.70.0030.01016.02
5.5.60.0040.01515.89
5.5.50.0000.01515.80
5.5.40.0100.00715.90
5.5.30.0000.01215.70
5.5.20.0070.00415.94
5.5.10.0030.01415.97
5.5.00.0070.00315.80

preferences:
43.66 ms | 400 KiB | 5 Q