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($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.60.0110.00716.88
8.3.50.0290.00821.99
8.3.40.0150.00018.92
8.3.30.0120.00318.94
8.3.20.0040.00420.29
8.3.10.0040.00423.48
8.3.00.0060.00319.80
8.2.180.0120.00318.34
8.2.170.0040.01122.96
8.2.160.0100.00319.46
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0060.00321.00
8.2.120.0050.00326.35
8.2.110.0060.00319.39
8.2.100.0040.00717.91
8.2.90.0040.00419.27
8.2.80.0000.00917.97
8.2.70.0070.00317.75
8.2.60.0100.00018.04
8.2.50.0060.00318.07
8.2.40.0040.00421.18
8.2.30.0050.00220.68
8.2.20.0080.00017.86
8.2.10.0040.00418.08
8.2.00.0050.00218.09
8.1.280.0100.00325.92
8.1.270.0090.00919.06
8.1.260.0070.00028.09
8.1.250.0050.00328.09
8.1.240.0060.00323.93
8.1.230.0040.00718.96
8.1.220.0080.00017.76
8.1.210.0080.00018.77
8.1.200.0060.00317.35
8.1.190.0040.00417.23
8.1.180.0040.00418.10
8.1.170.0050.00318.59
8.1.160.0020.00520.86
8.1.150.0040.00419.00
8.1.140.0000.00819.54
8.1.130.0000.00717.76
8.1.120.0040.00417.56
8.1.110.0070.00017.54
8.1.100.0040.00417.55
8.1.90.0000.00717.48
8.1.80.0040.00417.49
8.1.70.0000.00817.53
8.1.60.0040.00417.53
8.1.50.0030.00617.64
8.1.40.0050.00317.43
8.1.30.0000.00917.67
8.1.20.0040.00417.74
8.1.10.0000.00717.54
8.1.00.0000.00817.50
8.0.300.0040.00418.77
8.0.290.0040.00416.88
8.0.280.0050.00218.50
8.0.270.0030.00317.35
8.0.260.0000.00617.29
8.0.250.0070.00016.94
8.0.240.0040.00417.08
8.0.230.0050.00317.04
8.0.220.0060.00316.95
8.0.210.0050.00217.01
8.0.200.0070.00016.93
8.0.190.0050.00217.10
8.0.180.0070.00016.94
8.0.170.0000.00817.02
8.0.160.0000.00816.97
8.0.150.0000.00716.92
8.0.140.0060.00616.96
8.0.130.0030.00313.39
8.0.120.0080.00016.93
8.0.110.0040.00417.05
8.0.100.0030.00617.00
8.0.90.0000.00717.01
8.0.80.0100.00716.92
8.0.70.0040.00416.99
8.0.60.0050.00217.07
8.0.50.0060.00316.99
8.0.30.0060.01217.20
8.0.20.0110.00917.40
8.0.10.0080.00017.01
8.0.00.0090.00916.89
7.4.330.0050.00016.77
7.4.320.0000.00616.54
7.4.300.0040.00416.54
7.4.290.0000.00716.45
7.4.280.0030.00616.54
7.4.270.0000.00816.45
7.4.260.0000.00716.44
7.4.250.0000.00716.50
7.4.240.0010.00616.63
7.4.230.0050.00316.39
7.4.220.0120.00616.47
7.4.210.0140.00016.44
7.4.200.0050.00216.67
7.4.160.0130.00416.48
7.4.150.0060.01217.40
7.4.140.0130.00917.86
7.4.130.0140.00716.63
7.4.120.0090.00816.54
7.4.110.0060.01216.70
7.4.100.0070.01116.67
7.4.90.0060.01216.46
7.4.80.0100.01019.39
7.4.70.0130.01016.63
7.4.60.0140.00316.46
7.4.50.0060.01116.74
7.4.40.0090.00916.34
7.4.30.0100.01316.36
7.4.10.0080.00614.96
7.4.00.0060.01114.92
7.3.330.0030.00213.33
7.3.320.0050.00013.33
7.3.310.0000.00716.37
7.3.300.0000.00716.48
7.3.290.0070.00816.44
7.3.280.0070.01016.44
7.3.270.0120.00617.40
7.3.260.0090.01516.48
7.3.250.0130.00816.52
7.3.240.0130.00416.64
7.3.230.0040.01216.69
7.3.210.0120.00616.48
7.3.200.0290.00616.69
7.3.190.0140.00716.55
7.3.180.0120.00316.49
7.3.170.0060.01516.55
7.3.160.0090.01516.54
7.3.130.0040.01414.84
7.3.120.0030.00915.04
7.3.110.0030.01215.14
7.3.100.0060.01014.97
7.3.90.0030.01014.98
7.3.80.0080.00015.08
7.3.70.0140.00015.06
7.3.60.0030.01214.97
7.3.50.0100.00314.97
7.3.40.0080.00414.97
7.3.30.0130.00314.99
7.3.20.0100.00316.80
7.3.10.0000.01416.74
7.3.00.0090.00616.77
7.2.330.0100.00716.53
7.2.320.0110.01116.51
7.2.310.0090.00816.80
7.2.300.0100.00716.80
7.2.290.0070.01016.60
7.2.260.0090.00915.09
7.2.250.0060.01215.09
7.2.240.0030.01015.10
7.2.230.0040.01415.22
7.2.220.0060.00915.08
7.2.210.0040.00815.20
7.2.200.0060.00915.23
7.2.190.0000.01415.04
7.2.180.0000.01115.07
7.2.170.0000.01514.89
7.2.160.0060.00915.03
7.2.150.0060.00316.86
7.2.140.0040.00816.85
7.2.130.0040.01216.89
7.2.120.0030.00916.94
7.2.110.0030.01016.98
7.2.100.0110.00416.99
7.2.90.0040.01217.02
7.2.80.0030.01316.94
7.2.70.0040.00716.97
7.2.60.0070.00816.73
7.2.50.0030.00616.96
7.2.40.0030.00716.87
7.2.30.0050.00917.00
7.2.20.0060.00617.20
7.2.10.0060.00617.04
7.2.00.0050.01018.24
7.1.330.0060.00615.74
7.1.320.0060.00915.53
7.1.310.0070.00715.81
7.1.300.0060.00315.76
7.1.290.0000.01416.02
7.1.280.0060.01015.61
7.1.270.0060.00915.88
7.1.260.0060.00315.86
7.1.250.0040.00815.78
7.1.240.0030.00615.99
7.1.230.0040.00815.86
7.1.220.0070.00715.95
7.1.210.0090.00615.86
7.1.200.0100.00815.91
7.1.190.0080.00415.85
7.1.180.0030.01015.82
7.1.170.0060.00915.95
7.1.160.0030.01315.81
7.1.150.0030.01016.02
7.1.140.0090.00315.84
7.1.130.0040.01115.75
7.1.120.0070.00315.82
7.1.110.0000.01415.72
7.1.100.0040.00916.91
7.1.90.0030.00615.80
7.1.80.0070.00715.73
7.1.70.0050.00616.55
7.1.60.0050.01217.41
7.1.50.0080.00916.42
7.1.40.0030.01015.91
7.1.30.0000.01215.79
7.1.20.0060.00615.69
7.1.10.0140.00015.87
7.1.00.0090.03919.11
7.0.330.0070.00715.50
7.0.320.0030.01015.31
7.0.310.0070.01015.47
7.0.300.0000.01415.40
7.0.290.0030.01015.43
7.0.280.0070.00715.44
7.0.270.0040.00715.61
7.0.260.0070.00715.26
7.0.250.0070.00315.48
7.0.240.0040.00815.62
7.0.230.0060.01015.50
7.0.220.0070.00715.50
7.0.210.0130.00015.58
7.0.200.0030.00915.93
7.0.190.0000.01215.45
7.0.180.0110.00015.16
7.0.170.0140.00015.50
7.0.160.0060.00615.46
7.0.150.0080.00615.36
7.0.140.0100.00715.58
7.0.130.0030.00615.54
7.0.120.0070.00715.30
7.0.110.0110.00015.46
7.0.100.0000.01215.27
7.0.90.0030.00715.55
7.0.80.0040.01115.25
7.0.70.0040.00815.22
7.0.60.0050.04517.81
7.0.50.0030.02516.64
7.0.40.0050.05016.83
7.0.30.0200.03516.86
7.0.20.0230.03816.80
7.0.10.0070.02216.87
7.0.00.0070.04716.74
5.6.400.0030.00914.35
5.6.390.0000.01514.43
5.6.380.0140.00014.76
5.6.370.0060.01214.91
5.6.360.0040.01114.66
5.6.350.0040.00814.66
5.6.340.0040.00814.12
5.6.330.0090.00014.71
5.6.320.0040.00414.77
5.6.310.0070.00314.63
5.6.300.0020.00714.00
5.6.290.0070.00714.61
5.6.280.0030.03117.87
5.6.270.0030.00914.58
5.6.260.0000.01314.54
5.6.250.0030.01014.23
5.6.240.0070.00714.59
5.6.230.0060.01014.43
5.6.220.0030.01014.70
5.6.210.0050.02617.64
5.6.200.0050.04616.22
5.6.190.0120.03717.60
5.6.180.0100.05017.60
5.6.170.0080.04817.33
5.6.160.0020.04117.36
5.6.150.0060.02316.42
5.6.140.0100.04216.27
5.6.130.0110.04016.20
5.6.120.0070.02317.71
5.6.110.0060.04517.78
5.6.100.0120.02717.86
5.6.90.0080.04517.74
5.6.80.0070.04217.30
5.6.70.0090.00314.34
5.6.60.0030.01314.31
5.6.50.0060.00614.41
5.6.40.0070.01014.34
5.6.30.0000.01214.27
5.6.20.0000.01414.63
5.6.10.0060.00914.18
5.6.00.0000.00814.34
5.5.380.0090.00614.56
5.5.370.0100.00314.62
5.5.360.0030.01014.73
5.5.350.0220.03817.57
5.5.340.0130.02716.15
5.5.330.0050.04817.44
5.5.320.0170.04117.10
5.5.310.0130.04517.34
5.5.300.0080.04116.33
5.5.290.0030.05116.25
5.5.280.0060.04617.67
5.5.270.0050.04517.54
5.5.260.0050.02817.64
5.5.250.0050.03817.30
5.5.240.0020.03017.27
5.5.230.0060.00814.32
5.5.220.0040.00714.36
5.5.210.0090.00614.37
5.5.200.0040.00414.11
5.5.190.0040.01314.29
5.5.180.0060.01214.27
5.5.170.0030.01314.49
5.5.160.0080.00814.33
5.5.150.0060.01314.30
5.5.140.0160.00014.44
5.5.130.0070.01014.23
5.5.120.0060.00614.42
5.5.110.0090.00614.42
5.5.100.0070.00714.50
5.5.90.0040.01414.52
5.5.80.0060.00314.44
5.5.70.0040.00714.21
5.5.60.0060.00914.11
5.5.50.0070.00714.09
5.5.40.0030.01014.30
5.5.30.0040.01114.58
5.5.20.0030.00914.29
5.5.10.0000.01714.45
5.5.00.0070.01014.46

preferences:
49.95 ms | 401 KiB | 5 Q