3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CategoryTree { private $catTree = array(); public function addCategory($category, $parent) { if($parent == null){ //echo count(array_column($this->catTree, 'category')); if(count(array_column($this->catTree, 'category', $category)) > 0){ echo 'Duplicate category'; } else{ $temp = array("category" => $category,"parent" => $parent); array_push($this->catTree,$temp); } } else{ echo count(array_column($this->catTree, 'parent', $parent)); } } public function getChildren($parent) { $that = $this; $keys = array_keys(array_column($this->catTree, 'parent'), $parent); return array_map(function($k) use ($that){return $that->catTree[$k]['category'];}, $keys); } } // For testing purposes (do not submit uncommented): $c = new CategoryTree; $c->addCategory('A', null); $c->addCategory('A', null); $c->addCategory('B', 'A'); $c->addCategory('B', 'D'); $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.0040.01118.30
8.3.50.0120.01021.14
8.3.40.0040.01118.58
8.3.30.0070.01119.01
8.3.20.0030.00620.11
8.3.10.0070.00723.53
8.3.00.0030.00619.68
8.2.180.0110.01116.50
8.2.170.0140.00022.96
8.2.160.0000.01420.47
8.2.150.0000.01524.18
8.2.140.0080.00024.66
8.2.130.0000.00726.16
8.2.120.0130.00719.45
8.2.110.0040.00422.11
8.2.100.0090.00318.05
8.2.90.0040.00419.19
8.2.80.0060.00317.97
8.2.70.0080.00017.63
8.2.60.0000.00817.93
8.2.50.0080.00418.07
8.2.40.0080.00020.00
8.2.30.0080.00018.07
8.2.20.0050.00317.77
8.2.10.0020.00518.21
8.2.00.0040.00418.01
8.1.280.0070.00725.92
8.1.270.0030.00620.28
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0000.00822.01
8.1.230.0040.00719.08
8.1.220.0080.00017.74
8.1.210.0000.00918.77
8.1.200.0060.00317.47
8.1.190.0060.00317.13
8.1.180.0000.00918.10
8.1.170.0060.00318.66
8.1.160.0090.00022.00
8.1.150.0040.00418.79
8.1.140.0030.00617.44
8.1.130.0000.00917.76
8.1.120.0000.00917.48
8.1.110.0080.00017.37
8.1.100.0070.00017.51
8.1.90.0050.00317.36
8.1.80.0050.00217.50
8.1.70.0040.00417.38
8.1.60.0090.00017.66
8.1.50.0030.00617.52
8.1.40.0000.00817.53
8.1.30.0040.00417.64
8.1.20.0040.00417.70
8.1.10.0040.00417.64
8.1.00.0030.00617.45
8.0.300.0040.00418.77
8.0.290.0080.00016.88
8.0.280.0030.00518.40
8.0.270.0070.00017.33
8.0.260.0000.00617.26
8.0.250.0000.00716.96
8.0.240.0050.00316.97
8.0.230.0040.00416.95
8.0.220.0040.00416.84
8.0.210.0040.00416.81
8.0.200.0050.00316.96
8.0.190.0040.00416.97
8.0.180.0040.00416.82
8.0.170.0000.00816.95
8.0.160.0050.00316.80
8.0.150.0030.00716.78
8.0.140.0040.00416.82
8.0.130.0000.01013.40
8.0.120.0030.00616.80
8.0.110.0040.00416.82
8.0.100.0000.00816.68
8.0.90.0030.00716.93
8.0.80.0110.00516.86
8.0.70.0030.00516.84
8.0.60.0040.00416.80
8.0.50.0040.00416.91
8.0.30.0110.00617.06
8.0.20.0020.01717.40
8.0.10.0040.00416.89
8.0.00.0110.00816.86
7.4.330.0000.00515.09
7.4.320.0000.00616.54
7.4.300.0030.00316.52
7.4.290.0030.00316.54
7.4.280.0030.00316.59
7.4.270.0080.00016.47
7.4.260.0070.00316.59
7.4.250.0040.00416.39
7.4.240.0000.00716.60
7.4.230.0030.00316.59
7.4.220.0000.02016.56
7.4.210.0110.00716.49
7.4.200.0000.00716.64
7.4.160.0060.00916.60
7.4.150.0140.01117.40
7.4.140.0120.00817.86
7.4.130.0080.01416.59
7.4.120.0120.00816.64
7.4.110.0100.01316.50
7.4.100.0100.01016.38
7.4.90.0120.00616.42
7.4.80.0070.01019.39
7.4.70.0000.02116.57
7.4.60.0100.00716.55
7.4.50.0030.00316.60
7.4.40.0090.01216.43
7.4.30.0130.00916.67
7.4.00.0040.01114.78
7.3.330.0030.00613.23
7.3.320.0050.00013.25
7.3.310.0030.00316.34
7.3.300.0040.00416.23
7.3.290.0090.00616.39
7.3.280.0070.01116.34
7.3.270.0110.00517.40
7.3.260.0070.01416.74
7.3.250.0140.00616.46
7.3.240.0200.00316.31
7.3.230.0090.00916.39
7.3.210.0130.00316.66
7.3.200.0030.01419.39
7.3.190.0070.01016.52
7.3.180.0070.01016.45
7.3.170.0050.01116.29
7.3.160.0060.00916.52
7.2.330.0100.00716.82
7.2.320.0080.00816.49
7.2.310.0090.00616.80
7.2.300.0090.01316.70
7.2.290.0150.00616.67
7.2.60.0120.00317.01
7.2.00.0030.00719.65
7.1.200.0000.00915.53
7.1.100.0030.00917.94
7.1.70.0030.00617.15
7.1.60.0000.01619.86
7.1.50.0090.01517.10
7.1.00.0000.08022.35
7.0.200.0110.00315.05
7.0.60.0030.04019.89
7.0.50.0070.05017.81
7.0.40.0030.09020.18
7.0.30.0200.04720.13
7.0.20.0300.05020.10
7.0.10.0030.04320.05
7.0.00.0070.07020.12
5.6.280.0100.06721.05
5.6.210.0000.04320.76
5.6.200.0070.07018.22
5.6.190.0030.05320.48
5.6.180.0270.04720.57
5.6.170.0300.07720.48
5.6.160.0130.07720.43
5.6.150.0000.07318.18
5.6.140.0130.07318.12
5.6.130.0070.04018.24
5.6.120.0070.08320.99
5.6.110.0130.08321.01
5.6.100.0100.03721.11
5.6.90.0030.05721.14
5.6.80.0100.06320.54
5.5.350.0300.07020.45
5.5.340.0130.05318.09
5.5.330.0030.05320.40
5.5.320.0230.05020.42
5.5.310.0270.07720.27
5.5.300.0070.06318.04
5.5.290.0070.04018.07
5.5.280.0130.07720.82
5.5.270.0100.05720.79
5.5.260.0070.05020.77
5.5.250.0070.05320.70
5.5.240.0100.05320.37
5.4.450.0530.06019.44
5.4.440.0200.06319.66
5.4.430.0100.05319.56
5.4.420.0100.05019.36
5.4.410.0000.06019.30
5.4.400.0000.06019.16
5.4.390.0030.05319.13
5.4.380.0070.05319.16
5.4.370.0130.05019.13
5.4.360.0130.04319.25
5.4.350.0030.06319.21
5.4.340.0100.05319.07
5.4.320.0100.05319.02
5.4.310.0030.05719.21
5.4.300.0030.05319.24
5.4.290.0100.04719.06
5.4.280.0070.05719.02
5.4.270.0130.04319.05
5.4.260.0070.05319.10
5.4.250.0100.05319.11
5.4.240.0100.05319.02
5.4.230.0100.04719.10
5.4.220.0100.06319.20
5.4.210.0070.05019.05
5.4.200.0070.05016.97
5.4.190.0170.04019.01
5.4.180.0070.05319.03
5.4.170.0030.05719.14
5.4.160.0030.06019.14
5.4.150.0170.04319.00
5.4.140.0070.05016.53
5.4.130.0070.04716.64
5.4.120.0130.04016.61
5.4.110.0030.05016.31
5.4.100.0100.04716.52
5.4.90.0100.04716.67
5.4.80.0100.04316.34
5.4.70.0070.05016.67
5.4.60.0100.04316.45
5.4.50.0100.04316.26
5.4.40.0030.05316.22
5.4.30.0000.05316.44
5.4.20.0070.05016.31
5.4.10.0070.04716.44
5.4.00.0100.04315.77
5.3.290.0030.05714.84
5.3.280.0030.05714.54
5.3.270.0030.07314.73
5.3.260.0130.04714.55
5.3.250.0030.05314.61
5.3.240.0070.05014.52
5.3.230.0130.04714.47
5.3.220.0070.05014.59
5.3.210.0130.04714.58
5.3.200.0130.04314.61
5.3.190.0070.05314.50
5.3.180.0100.04714.48
5.3.170.0100.04714.59
5.3.160.0030.07314.73
5.3.150.0070.05014.56
5.3.140.0000.05714.49
5.3.130.0070.05314.57
5.3.120.0070.05314.57
5.3.110.0070.05314.70
5.3.100.0000.05714.05
5.3.90.0170.04014.18
5.3.80.0030.05314.01
5.3.70.0070.05014.02
5.3.60.0170.05713.87
5.3.50.0100.05013.86
5.3.40.0000.05714.16
5.3.30.0070.06713.98
5.3.20.0100.06313.79
5.3.10.0100.04713.65
5.3.00.0070.05013.61
5.2.170.0030.04311.21
5.2.160.0070.03711.06
5.2.150.0000.04711.14
5.2.140.0000.04711.13
5.2.130.0030.04011.02
5.2.120.0070.04011.03
5.2.110.0100.03311.27
5.2.100.0100.05010.97
5.2.90.0070.05311.27
5.2.80.0100.03711.07
5.2.70.0030.04311.08
5.2.60.0100.04011.05
5.2.50.0100.04010.92
5.2.40.0070.04011.07
5.2.30.0100.03710.98
5.2.20.0030.04010.88
5.2.10.0030.04010.79
5.2.00.0170.02710.58
5.1.60.0000.03710.16
5.1.50.0030.0339.93
5.1.40.0030.0339.90
5.1.30.0030.03710.29
5.1.20.0000.04010.34
5.1.10.0070.03310.19
5.1.00.0030.03710.08
5.0.50.0000.0308.49
5.0.40.0030.0278.41
5.0.30.0170.0308.13
5.0.20.0000.0308.27
5.0.10.0030.0278.24
5.0.00.0070.0378.16
4.4.90.0000.0235.86
4.4.80.0000.0235.92
4.4.70.0030.0205.77
4.4.60.0000.0275.74
4.4.50.0000.0235.74
4.4.40.0030.0335.88
4.4.30.0030.0205.74
4.4.20.0030.0205.80
4.4.10.0000.0235.95
4.4.00.0000.0375.87
4.3.110.0000.0235.70
4.3.100.0100.0135.80
4.3.90.0000.0235.76
4.3.80.0000.0335.78
4.3.70.0000.0205.76
4.3.60.0000.0235.65
4.3.50.0000.0235.82
4.3.40.0070.0275.69
4.3.30.0000.0234.54
4.3.20.0030.0204.49
4.3.10.0000.0234.43
4.3.00.0130.0276.98

preferences:
45.29 ms | 401 KiB | 5 Q