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(); } 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.60.0140.00016.75
8.3.50.0070.01222.04
8.3.40.0090.00918.88
8.3.30.0070.00718.92
8.3.20.0090.00020.36
8.3.10.0060.00323.71
8.3.00.0040.00419.91
8.2.180.0060.01518.66
8.2.170.0070.01422.96
8.2.160.0100.00319.58
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00421.04
8.2.110.0070.00321.07
8.2.100.0060.00618.03
8.2.90.0030.00619.39
8.2.80.0050.00317.97
8.2.70.0030.00517.75
8.2.60.0070.00317.93
8.2.50.0030.00518.10
8.2.40.0030.00619.39
8.2.30.0040.00420.65
8.2.20.0080.00017.91
8.2.10.0040.00418.03
8.2.00.0040.00418.22
8.1.280.0000.01625.92
8.1.270.0000.00820.73
8.1.260.0030.00526.35
8.1.250.0070.00028.09
8.1.240.0070.00321.38
8.1.230.0070.00719.54
8.1.220.0050.00317.74
8.1.210.0060.00318.77
8.1.200.0000.00917.36
8.1.190.0080.00017.35
8.1.180.0030.00618.10
8.1.170.0000.00918.43
8.1.160.0040.00420.91
8.1.150.0000.00718.94
8.1.140.0040.00419.53
8.1.130.0040.00417.75
8.1.120.0040.00417.50
8.1.110.0000.00717.55
8.1.100.0000.00917.55
8.1.90.0040.00417.45
8.1.80.0040.00417.50
8.1.70.0070.00017.55
8.1.60.0040.00417.64
8.1.50.0000.00817.46
8.1.40.0040.00417.60
8.1.30.0030.00517.64
8.1.20.0040.00417.59
8.1.10.0000.00717.64
8.1.00.0050.00317.49
8.0.300.0000.00718.77
8.0.290.0080.00016.88
8.0.280.0070.00018.37
8.0.270.0070.00017.18
8.0.260.0030.00317.34
8.0.250.0000.00817.03
8.0.240.0040.00417.07
8.0.230.0030.00317.05
8.0.220.0040.00416.87
8.0.210.0070.00016.89
8.0.200.0030.00317.04
8.0.190.0040.00416.95
8.0.180.0020.00517.04
8.0.170.0060.00317.05
8.0.160.0040.00417.01
8.0.150.0030.00516.87
8.0.140.0000.00716.80
8.0.130.0000.00613.48
8.0.120.0080.00016.95
8.0.110.0040.00417.00
8.0.100.0000.00717.09
8.0.90.0040.00417.03
8.0.80.0090.00616.91
8.0.70.0040.00416.93
8.0.60.0040.00416.95
8.0.50.0040.00416.91
8.0.30.0060.00917.18
8.0.20.0110.01117.42
8.0.10.0080.00017.23
8.0.00.0110.00916.76
7.4.330.0000.00516.80
7.4.320.0080.00016.62
7.4.300.0070.00016.53
7.4.290.0030.00316.64
7.4.280.0000.00916.52
7.4.270.0030.00316.65
7.4.260.0000.00716.62
7.4.250.0050.00316.50
7.4.240.0050.00216.49
7.4.230.0070.00016.64
7.4.220.0130.00616.50
7.4.210.0060.00916.66
7.4.200.0000.00716.64
7.4.160.0100.01316.55
7.4.150.0120.00617.40
7.4.140.0120.01017.86
7.4.130.0080.01016.56
7.4.120.0080.00916.79
7.4.110.0130.00616.53
7.4.100.0060.01516.61
7.4.90.0040.01216.46
7.4.80.0100.01319.39
7.4.70.0130.00416.54
7.4.60.0090.00616.51
7.4.50.0100.00716.67
7.4.40.0150.00716.73
7.4.30.0100.00616.48
7.4.00.0100.00714.97
7.3.330.0030.00313.43
7.3.320.0060.00013.42
7.3.310.0070.00016.47
7.3.300.0000.00716.46
7.3.290.0090.00516.47
7.3.280.0080.00816.44
7.3.270.0150.00317.40
7.3.260.0100.00716.73
7.3.250.0150.00816.47
7.3.240.0120.00416.58
7.3.230.0080.00916.65
7.3.210.0110.00716.41
7.3.200.0090.01316.29
7.3.190.0080.00816.33
7.3.180.0140.00316.42
7.3.170.0050.01116.52
7.3.160.0200.00316.65
7.3.10.0040.01216.69
7.3.00.0080.00116.79
7.2.330.0090.00916.78
7.2.320.0120.00616.66
7.2.310.0070.01616.78
7.2.300.0040.01416.73
7.2.290.0100.01416.59
7.2.130.0030.01016.96
7.2.120.0050.00917.08
7.2.110.0090.00316.90
7.2.100.0030.01016.78
7.2.90.0020.01416.97
7.2.80.0060.00717.06
7.2.70.0060.00616.99
7.2.60.0060.01017.02
7.2.50.0060.00816.94
7.2.40.0020.01216.99
7.2.30.0050.00916.94
7.2.20.0020.01116.90
7.2.10.0080.00216.85
7.2.00.0050.00616.87
7.1.250.0050.00715.71
7.1.240.0040.00815.75
7.1.230.0000.01115.55
7.1.220.0070.00315.56
7.1.210.0030.01315.85
7.1.200.0050.00715.67
7.1.190.0000.01215.59
7.1.180.0000.01015.79
7.1.170.0070.00415.97
7.1.160.0000.01215.94
7.1.150.0090.00315.98
7.1.140.0030.00915.77
7.1.130.0070.00415.74
7.1.120.0100.00315.82
7.1.110.0030.00715.98
7.1.100.0050.00716.61
7.1.90.0030.00715.88
7.1.80.0060.00615.70
7.1.70.0080.00416.54
7.1.60.0010.01116.38
7.1.50.0050.01216.35
7.1.40.0080.00415.69
7.1.30.0140.01024.94
7.1.20.0060.00615.82
7.1.10.0040.00415.92
7.1.00.0030.04319.14
7.0.330.0000.01015.41
7.0.320.0100.00015.47
7.0.310.0070.00315.32
7.0.300.0070.00415.37
7.0.290.0070.00415.13
7.0.280.0000.01315.40
7.0.270.0120.00315.45
7.0.260.0060.00915.53
7.0.250.0030.01015.14
7.0.240.0060.00315.53
7.0.230.0050.00515.23
7.0.220.0040.00815.45
7.0.210.0070.00415.38
7.0.200.0080.00615.96
7.0.190.0060.00615.42
7.0.180.0120.00015.48
7.0.170.0060.00615.49
7.0.160.0080.00315.35
7.0.150.0030.00615.50
7.0.140.0120.00315.41
7.0.130.0080.00015.53
7.0.120.0030.00715.25
7.0.110.0060.00615.22
7.0.100.0040.00715.55
7.0.90.0060.00315.36
7.0.80.0000.00915.05
7.0.70.0060.00615.18
7.0.60.0020.02517.73
7.0.50.0060.02316.64
7.0.40.0040.02716.72
7.0.30.0030.03016.87
7.0.20.0200.03316.81
7.0.10.0050.03416.83
7.0.00.0070.03316.81
5.6.380.0060.00614.63
5.6.370.0110.00014.67
5.6.360.0040.00714.23
5.6.350.0130.00014.46
5.6.340.0070.00314.33
5.6.330.0060.00614.21
5.6.320.0060.00614.05
5.6.310.0040.00714.33
5.6.300.0030.00914.43
5.6.290.0040.00814.33
5.6.280.0070.01817.64
5.6.270.0030.01214.61
5.6.260.0110.00014.56
5.6.250.0040.00814.51
5.6.240.0080.00414.06
5.6.230.0050.00514.38
5.6.220.0040.00714.23
5.6.210.0070.03917.61
5.6.200.0060.04216.35
5.6.190.0130.04217.46
5.6.180.0130.03517.33
5.6.170.0200.03717.50
5.6.160.0080.03517.44
5.6.150.0050.04516.16
5.6.140.0080.04216.23
5.6.130.0070.03016.40
5.6.120.0070.02517.72
5.6.110.0050.04017.64
5.6.100.0030.03717.77
5.6.90.0100.04017.61
5.6.80.0050.04417.30
5.6.70.0040.00414.36
5.6.60.0030.00914.32
5.6.50.0040.01114.20
5.6.40.0030.00714.11
5.6.30.0000.01214.09
5.6.20.0000.00914.06
5.6.10.0040.00814.26
5.6.00.0100.00313.95
5.5.380.0050.00511.37
5.5.370.0000.00811.25
5.5.360.0090.00011.46
5.5.350.0160.02115.62
5.5.340.0110.03814.58
5.5.330.0070.04015.77
5.5.320.0130.04015.77
5.5.310.0030.03215.93
5.5.300.0020.03014.48
5.5.290.0060.03814.52
5.5.280.0030.03215.98
5.5.270.0060.02816.02
5.5.260.0110.03015.88
5.5.250.0120.04415.80
5.5.240.0080.04315.59
5.5.230.0030.00711.27
5.5.220.0070.00410.95
5.5.210.0050.00210.90
5.5.200.0060.00310.93
5.5.190.0050.00511.28
5.5.180.0070.00311.30
5.5.170.0030.00311.00
5.5.160.0040.00410.90
5.5.150.0000.01111.31
5.5.140.0070.00311.07
5.5.130.0000.00810.90
5.5.120.0040.00410.93
5.5.110.0060.00311.07
5.5.100.0060.00010.93
5.5.90.0040.00710.97
5.5.80.0000.01011.03
5.5.70.0000.00811.24
5.5.60.0030.00611.19
5.5.50.0000.01110.95
5.5.40.0090.00311.00
5.5.30.0040.00410.96
5.5.20.0040.00410.98
5.5.10.0000.00911.14
5.5.00.0030.00610.93

preferences:
43.74 ms | 401 KiB | 5 Q