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{ if(count(array_column($this->catTree, 'parent', $parent)) == 0){ echo 'Parent not found'; } else{ $temp = array("category" => $category,"parent" => $parent); array_push($this->catTree,$temp); } } } 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.0060.01618.55
8.3.50.0130.00621.28
8.3.40.0060.00918.67
8.3.30.0080.00818.90
8.3.20.0040.00420.29
8.3.10.0090.00923.52
8.3.00.0050.00319.68
8.2.180.0040.01416.50
8.2.170.0080.01222.96
8.2.160.0100.00320.39
8.2.150.0030.00624.18
8.2.140.0040.00424.66
8.2.130.0050.00226.16
8.2.120.0000.01519.48
8.2.110.0060.00322.07
8.2.100.0090.00318.22
8.2.90.0000.00919.22
8.2.80.0060.00317.97
8.2.70.0000.00817.38
8.2.60.0030.00617.93
8.2.50.0030.00618.07
8.2.40.0030.00620.07
8.2.30.0000.00818.23
8.2.20.0000.00817.77
8.2.10.0040.00418.05
8.2.00.0030.00618.07
8.1.280.0040.01125.92
8.1.270.0080.00020.33
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0000.00923.82
8.1.230.0040.00819.11
8.1.220.0040.00417.74
8.1.210.0000.00818.77
8.1.200.0060.00317.35
8.1.190.0040.00417.35
8.1.180.0040.00418.10
8.1.170.0040.00418.59
8.1.160.0050.00322.06
8.1.150.0000.00718.84
8.1.140.0040.00717.50
8.1.130.0040.00417.88
8.1.120.0000.00817.50
8.1.110.0050.00217.51
8.1.100.0030.00517.54
8.1.90.0040.00417.51
8.1.80.0000.00717.50
8.1.70.0040.00417.49
8.1.60.0040.00417.65
8.1.50.0030.00517.48
8.1.40.0040.00417.54
8.1.30.0000.00817.72
8.1.20.0000.00817.62
8.1.10.0000.00817.52
8.1.00.0030.00617.45
8.0.300.0000.00718.77
8.0.290.0070.00016.88
8.0.280.0030.00618.50
8.0.270.0000.00717.22
8.0.260.0030.00317.29
8.0.250.0000.00717.00
8.0.240.0030.00517.02
8.0.230.0020.00516.89
8.0.220.0000.00716.86
8.0.210.0000.00716.86
8.0.200.0000.00616.89
8.0.190.0030.00616.93
8.0.180.0000.00716.99
8.0.170.0040.00416.96
8.0.160.0030.00516.84
8.0.150.0040.00416.86
8.0.140.0050.00516.83
8.0.130.0000.00813.44
8.0.120.0040.00416.80
8.0.110.0000.00716.99
8.0.100.0000.00716.86
8.0.90.0070.00316.82
8.0.80.0130.00316.86
8.0.70.0040.00416.93
8.0.60.0040.00416.79
8.0.50.0040.00416.80
8.0.30.0070.01217.12
8.0.20.0100.01117.40
8.0.10.0040.00416.86
8.0.00.0120.00816.76
7.4.330.0000.00515.03
7.4.320.0060.00016.50
7.4.300.0070.00016.46
7.4.290.0040.00416.46
7.4.280.0030.00316.50
7.4.270.0000.00816.49
7.4.260.0030.00316.65
7.4.250.0030.00316.60
7.4.240.0020.00516.57
7.4.230.0070.00016.62
7.4.220.0060.01316.58
7.4.210.0070.01416.57
7.4.200.0000.00716.44
7.4.160.0090.00916.52
7.4.150.0150.00417.40
7.4.140.0180.00517.86
7.4.130.0060.01116.52
7.4.120.0090.00816.54
7.4.110.0130.00716.46
7.4.100.0100.01016.46
7.4.90.0130.00416.52
7.4.80.0060.01019.39
7.4.70.0150.00316.41
7.4.60.0130.00316.63
7.4.50.0000.00616.46
7.4.40.0070.01516.51
7.4.30.0040.01416.73
7.4.00.0110.00415.15
7.3.330.0040.00413.33
7.3.320.0000.00513.36
7.3.310.0070.00016.28
7.3.300.0000.00616.41
7.3.290.0080.01016.36
7.3.280.0080.01116.35
7.3.270.0070.01417.40
7.3.260.0120.00616.65
7.3.250.0130.00516.40
7.3.240.0100.00716.48
7.3.230.0030.02016.47
7.3.210.0160.00716.53
7.3.200.0070.01019.39
7.3.190.0060.01516.47
7.3.180.0080.00816.68
7.3.170.0000.01616.72
7.3.160.0040.01316.57
7.2.330.0060.02116.82
7.2.320.0090.00916.39
7.2.310.0090.01216.91
7.2.300.0110.00616.52
7.2.290.0030.02016.80
7.2.00.0030.01019.65
7.1.100.0060.00618.30
7.1.70.0060.00317.14
7.1.60.0080.01519.86
7.1.50.0090.01616.61
7.1.00.0070.07322.29
7.0.200.0040.00715.00
7.0.60.0070.07319.89
7.0.50.0030.09017.91
7.0.40.0070.08720.35
7.0.30.0230.04320.07
7.0.20.0230.08020.06
7.0.10.0070.08720.22
7.0.00.0030.07720.23
5.6.280.0070.07020.83
5.6.210.0030.08320.63
5.6.200.0100.08318.29
5.6.190.0070.08720.33
5.6.180.0430.05720.51
5.6.170.0230.07720.41
5.6.160.0000.04720.44
5.6.150.0030.08318.25
5.6.140.0030.09318.21
5.6.130.0000.08018.14
5.6.120.0100.08721.02
5.6.110.0070.06321.13
5.6.100.0100.04721.01
5.6.90.0130.07020.98
5.6.80.0170.05320.39
5.5.350.0330.05720.42
5.5.340.0100.07317.95
5.5.330.0070.06720.31
5.5.320.0300.07720.30
5.5.310.0330.08320.27
5.5.300.0030.05718.04
5.5.290.0100.05017.98
5.5.280.0000.04320.70
5.5.270.0070.07320.77
5.5.260.0030.06720.89
5.5.250.0030.05720.71
5.5.240.0030.07720.30
5.4.450.0800.04319.55
5.4.440.0930.05019.43
5.4.430.0170.05719.55
5.4.420.0070.06019.48
5.4.410.0070.05019.25
5.4.400.0000.06019.23
5.4.390.0000.06019.14
5.4.380.0100.05019.04
5.4.370.0170.04319.09
5.4.360.0130.04719.07
5.4.350.0070.05319.08
5.4.340.0030.06019.09
5.4.320.0100.05019.07
5.4.310.0100.05319.21
5.4.300.0130.04719.16
5.4.290.0130.04319.16
5.4.280.0100.04719.23
5.4.270.0070.05019.15
5.4.260.0100.05019.05
5.4.250.0130.04719.08
5.4.240.0130.04719.01
5.4.230.0100.05019.12
5.4.220.0030.06019.25
5.4.210.0100.05019.05
5.4.200.0030.05316.64
5.4.190.0100.04719.09
5.4.180.0070.05019.09
5.4.170.0070.05319.11
5.4.160.0070.05019.10
5.4.150.0030.05719.04
5.4.140.0030.05716.35
5.4.130.0070.04716.33
5.4.120.0070.05016.50
5.4.110.0130.04316.30
5.4.100.0170.04716.52
5.4.90.0030.05316.54
5.4.80.0070.05016.47
5.4.70.0130.04316.50
5.4.60.0030.05316.31
5.4.50.0030.05016.44
5.4.40.0070.05016.41
5.4.30.0030.05016.38
5.4.20.0030.05316.54
5.4.10.0130.04316.22
5.4.00.0070.05015.71
5.3.290.0030.05714.61
5.3.280.0030.05714.62
5.3.270.0070.05314.55
5.3.260.0030.05714.73
5.3.250.0030.05314.58
5.3.240.0030.05314.47
5.3.230.0030.05714.77
5.3.220.0070.05014.49
5.3.210.0070.05714.61
5.3.200.0030.05314.62
5.3.190.0000.06314.49
5.3.180.0070.05014.76
5.3.170.0030.05314.54
5.3.160.0030.05314.49
5.3.150.0100.04714.56
5.3.140.0030.05314.65
5.3.130.0070.05314.57
5.3.120.0070.05714.42
5.3.110.0130.04714.52
5.3.100.0030.05314.06
5.3.90.0130.05013.90
5.3.80.0070.05314.06
5.3.70.0030.06314.02
5.3.60.0170.04314.00
5.3.50.0200.04013.97
5.3.40.0000.06013.95
5.3.30.0070.05013.84
5.3.20.0130.04713.61
5.3.10.0030.05013.60
5.3.00.0070.04713.81
5.2.170.0030.04311.12
5.2.160.0070.03711.13
5.2.150.0030.04311.14
5.2.140.0030.04311.26
5.2.130.0070.03711.27
5.2.120.0070.03711.02
5.2.110.0100.04311.09
5.2.100.0030.04011.07
5.2.90.0030.04011.06
5.2.80.0030.04311.27
5.2.70.0000.04711.05
5.2.60.0000.04710.96
5.2.50.0100.04011.19
5.2.40.0130.03011.15
5.2.30.0000.04710.97
5.2.20.0030.04311.04
5.2.10.0030.04010.88
5.2.00.0000.04310.72
5.1.60.0070.0309.90
5.1.50.0030.03710.08
5.1.40.0070.0439.99
5.1.30.0070.03310.25
5.1.20.0070.03310.52
5.1.10.0000.04010.14
5.1.00.0000.04010.14
5.0.50.0100.0208.47
5.0.40.0000.0378.53
5.0.30.0100.0378.37
5.0.20.0070.0238.14
5.0.10.0000.0308.07
5.0.00.0030.0408.33
4.4.90.0070.0175.79
4.4.80.0000.0235.74
4.4.70.0000.0235.73
4.4.60.0100.0175.85
4.4.50.0000.0235.90
4.4.40.0070.0305.74
4.4.30.0100.0135.90
4.4.20.0030.0205.80
4.4.10.0000.0235.81
4.4.00.0030.0335.88
4.3.110.0070.0175.79
4.3.100.0000.0235.68
4.3.90.0000.0235.68
4.3.80.0030.0335.68
4.3.70.0100.0135.65
4.3.60.0070.0135.83
4.3.50.0030.0275.82
4.3.40.0000.0375.76
4.3.30.0000.0234.53
4.3.20.0000.0304.52
4.3.10.0000.0234.49
4.3.00.0070.0306.98

preferences:
61.9 ms | 401 KiB | 5 Q