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)) < 1){ 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.0090.00918.52
8.3.50.0140.00321.11
8.3.40.0080.01118.85
8.3.30.0090.00619.22
8.3.20.0040.00420.34
8.3.10.0120.00623.32
8.3.00.0030.00619.56
8.2.180.0120.00616.63
8.2.170.0120.00619.08
8.2.160.0130.00722.96
8.2.150.0080.00024.18
8.2.140.0070.00024.66
8.2.130.0020.00526.16
8.2.120.0070.00719.36
8.2.110.0060.00322.06
8.2.100.0080.00418.16
8.2.90.0030.00619.10
8.2.80.0000.00817.97
8.2.70.0000.00917.63
8.2.60.0080.00017.80
8.2.50.0100.00018.07
8.2.40.0030.00620.01
8.2.30.0000.00818.30
8.2.20.0080.00017.84
8.2.10.0000.00718.23
8.2.00.0040.00418.13
8.1.280.0120.00325.92
8.1.270.0040.00420.38
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0070.00323.90
8.1.230.0110.00019.22
8.1.220.0050.00317.77
8.1.210.0040.00418.77
8.1.200.0100.00017.35
8.1.190.0090.00017.35
8.1.180.0030.00518.10
8.1.170.0000.00818.65
8.1.160.0040.00422.06
8.1.150.0040.00418.85
8.1.140.0000.00917.56
8.1.130.0040.00417.79
8.1.120.0040.00417.55
8.1.110.0080.00017.39
8.1.100.0000.00817.38
8.1.90.0020.00517.56
8.1.80.0040.00417.51
8.1.70.0030.00517.56
8.1.60.0000.01017.60
8.1.50.0000.01217.62
8.1.40.0040.00417.44
8.1.30.0060.00317.61
8.1.20.0030.00617.56
8.1.10.0050.00217.50
8.1.00.0000.00717.55
8.0.300.0090.00018.77
8.0.290.0040.00416.75
8.0.280.0030.00618.47
8.0.270.0000.00717.21
8.0.260.0000.00717.21
8.0.250.0000.00816.89
8.0.240.0050.00317.04
8.0.230.0030.00316.90
8.0.220.0000.00716.86
8.0.210.0070.00016.93
8.0.200.0030.00316.88
8.0.190.0040.00416.89
8.0.180.0020.00516.80
8.0.170.0040.00416.94
8.0.160.0030.00516.89
8.0.150.0070.00016.85
8.0.140.0030.00616.80
8.0.130.0000.00913.36
8.0.120.0050.00216.85
8.0.110.0080.00016.89
8.0.100.0040.00416.88
8.0.90.0030.00616.80
8.0.80.0130.00316.92
8.0.70.0050.00317.00
8.0.60.0040.00416.78
8.0.50.0050.00316.97
8.0.30.0080.01117.14
8.0.20.0130.01017.40
8.0.10.0040.00417.01
8.0.00.0110.00616.63
7.4.330.0000.00615.09
7.4.320.0060.00016.45
7.4.300.0000.00616.64
7.4.290.0000.00816.55
7.4.280.0000.00716.53
7.4.270.0000.00816.64
7.4.260.0030.00616.59
7.4.250.0000.00716.60
7.4.240.0070.00016.63
7.4.230.0030.00316.75
7.4.220.0060.01316.59
7.4.210.0080.00816.67
7.4.200.0050.00316.70
7.4.160.0070.01016.62
7.4.150.0060.01217.40
7.4.140.0130.00617.86
7.4.130.0120.00616.61
7.4.120.0100.01116.53
7.4.110.0100.00716.61
7.4.100.0090.01116.41
7.4.90.0070.01116.50
7.4.80.0110.00719.39
7.4.70.0140.00316.48
7.4.60.0070.01016.67
7.4.50.0000.00816.19
7.4.40.0090.00916.39
7.4.30.0190.00316.59
7.4.00.0020.01514.97
7.3.330.0040.00413.41
7.3.320.0000.00613.43
7.3.310.0070.00016.31
7.3.300.0000.00716.27
7.3.290.0070.00816.40
7.3.280.0050.01416.39
7.3.270.0030.01417.40
7.3.260.0090.00916.72
7.3.250.0090.01116.46
7.3.240.0170.00016.39
7.3.230.0100.00716.43
7.3.210.0030.01516.35
7.3.200.0170.00019.39
7.3.190.0110.00716.60
7.3.180.0130.00316.50
7.3.170.0100.00616.36
7.3.160.0080.00816.48
7.3.120.0030.01015.02
7.3.110.0070.01014.91
7.3.100.0000.01214.92
7.3.90.0000.00915.04
7.3.80.0070.00415.12
7.3.70.0060.00314.96
7.3.60.0040.00414.60
7.3.50.0090.00614.90
7.3.40.0040.01114.68
7.3.30.0060.00314.86
7.3.20.0070.00716.50
7.3.10.0040.01116.63
7.3.00.0030.00716.50
7.2.330.0060.01216.78
7.2.320.0060.01516.77
7.2.310.0170.00716.67
7.2.300.0060.01216.86
7.2.290.0130.00916.83
7.2.250.0070.01015.07
7.2.240.0030.01315.26
7.2.230.0030.01015.22
7.2.220.0090.00615.29
7.2.210.0040.01114.98
7.2.200.0110.00415.03
7.2.190.0080.00815.25
7.2.180.0030.01015.08
7.2.170.0070.00715.25
7.2.00.0080.00419.46
7.1.330.0070.00715.86
7.1.320.0040.01115.84
7.1.310.0060.00615.67
7.1.300.0030.00615.61
7.1.290.0110.00415.77
7.1.280.0100.00015.81
7.1.270.0060.00915.80
7.1.260.0060.00615.62
7.1.200.0060.00315.59
7.1.100.0040.01118.19
7.1.70.0060.00317.30
7.1.60.0030.02019.86
7.1.50.0160.00616.70
7.1.00.0000.08022.51
7.0.200.0060.00615.15
7.0.60.0030.05320.04
7.0.50.0030.04317.88
7.0.40.0000.05720.09
7.0.30.0200.04320.21
7.0.20.0330.06020.33
7.0.10.0000.04720.09
7.0.00.0070.09020.33
5.6.280.0070.07020.93
5.6.210.0130.07720.68
5.6.200.0000.05318.27
5.6.190.0070.05020.61
5.6.180.0330.04720.61
5.6.170.0200.08020.62
5.6.160.0100.08020.47
5.6.150.0070.07018.29
5.6.140.0030.05718.23
5.6.130.0100.07718.12
5.6.120.0070.04320.91
5.6.110.0130.03320.99
5.6.100.0170.06021.13
5.6.90.0030.06021.12
5.6.80.0130.05020.37
5.5.350.0200.08320.42
5.5.340.0070.07018.04
5.5.330.0100.05020.30
5.5.320.0300.06720.34
5.5.310.0330.07720.24
5.5.300.0030.05717.98
5.5.290.0100.05318.05
5.5.280.0000.04320.89
5.5.270.0030.04720.95
5.5.260.0070.08320.78
5.5.250.0030.05720.49
5.5.240.0130.05320.17
5.4.450.0630.04719.45
5.4.440.0630.05719.68
5.4.430.0170.06319.63
5.4.420.0170.06719.52
5.4.410.0070.05319.42
5.4.400.0100.05718.91
5.4.390.0070.05319.13
5.4.380.0100.05019.13
5.4.370.0070.05319.16
5.4.360.0070.05019.25
5.4.350.0100.05319.03
5.4.340.0130.05019.11
5.4.320.0130.05019.14
5.4.310.0100.04719.06
5.4.300.0100.04719.08
5.4.290.0100.05319.13
5.4.280.0100.05019.08
5.4.270.0030.05319.20
5.4.260.0030.05719.05
5.4.250.0030.06319.06
5.4.240.0070.05319.07
5.4.230.0000.05719.05
5.4.220.0100.05019.02
5.4.210.0030.05719.10
5.4.200.0100.04716.97
5.4.190.0030.05719.02
5.4.180.0170.04319.14
5.4.170.0100.05719.14
5.4.160.0030.05719.10
5.4.150.0030.06719.04
5.4.140.0030.05716.47
5.4.130.0070.05016.63
5.4.120.0100.05716.53
5.4.110.0130.05016.63
5.4.100.0000.05716.30
5.4.90.0030.05316.29
5.4.80.0000.06316.61
5.4.70.0170.05016.27
5.4.60.0100.05716.44
5.4.50.0070.05016.56
5.4.40.0100.06016.55
5.4.30.0100.04316.44
5.4.20.0030.06016.26
5.4.10.0030.05016.55
5.4.00.0100.04715.74
5.3.290.0100.05014.71
5.3.280.0100.05014.57
5.3.270.0130.05014.54
5.3.260.0100.05014.67
5.3.250.0130.04714.68
5.3.240.0100.05314.65
5.3.230.0000.05714.68
5.3.220.0130.04714.59
5.3.210.0100.05014.74
5.3.200.0070.05014.44
5.3.190.0170.04314.59
5.3.180.0070.05014.59
5.3.170.0030.05314.59
5.3.160.0130.04314.50
5.3.150.0030.05014.49
5.3.140.0000.05714.55
5.3.130.0130.04714.59
5.3.120.0070.05014.71
5.3.110.0100.05314.64
5.3.100.0030.05013.96
5.3.90.0100.04314.04
5.3.80.0100.04714.20
5.3.70.0070.04713.93
5.3.60.0070.05013.93
5.3.50.0170.04713.93
5.3.40.0230.05013.93
5.3.30.0100.04314.04
5.3.20.0000.05713.86
5.3.10.0200.03313.60
5.3.00.0070.05013.71
5.2.170.0100.03711.11
5.2.160.0030.04011.07
5.2.150.0070.04011.06
5.2.140.0030.04011.06
5.2.130.0070.03711.22
5.2.120.0130.03311.03
5.2.110.0070.03711.05
5.2.100.0070.04311.22
5.2.90.0100.04311.07
5.2.80.0030.04711.21
5.2.70.0130.03311.27
5.2.60.0030.04310.98
5.2.50.0100.03710.95
5.2.40.0100.03310.98
5.2.30.0030.04311.05
5.2.20.0000.04710.97
5.2.10.0030.04011.02
5.2.00.0030.04310.67
5.1.60.0000.03710.05
5.1.50.0070.0339.93
5.1.40.0030.0379.98
5.1.30.0000.04010.29
5.1.20.0030.03710.39
5.1.10.0000.04010.13
5.1.00.0030.03710.17
5.0.50.0030.0278.44
5.0.40.0030.0278.42
5.0.30.0000.0438.16
5.0.20.0000.0308.21
5.0.10.0030.0278.27
5.0.00.0070.0378.18
4.4.90.0000.0235.87
4.4.80.0000.0235.73
4.4.70.0030.0205.87
4.4.60.0000.0235.84
4.4.50.0100.0135.80
4.4.40.0100.0275.88
4.4.30.0100.0135.90
4.4.20.0000.0235.91
4.4.10.0000.0235.95
4.4.00.0070.0405.86
4.3.110.0000.0235.76
4.3.100.0070.0175.66
4.3.90.0000.0235.73
4.3.80.0030.0335.64
4.3.70.0000.0235.65
4.3.60.0000.0235.75
4.3.50.0070.0175.65
4.3.40.0000.0335.66
4.3.30.0100.0134.45
4.3.20.0000.0304.52
4.3.10.0000.0234.48
4.3.00.0100.0276.98

preferences:
50.73 ms | 401 KiB | 5 Q