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 'Parent: ' . $parent; //print_r(array_column($this->catTree, 'parent', $parent)); print_r(array_keys(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.40.0090.00618.86
8.3.30.0060.00919.09
8.3.20.0000.00820.34
8.3.10.0030.00523.56
8.3.00.0090.00019.61
8.2.170.0100.01022.96
8.2.160.0070.01320.46
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0080.00019.17
8.2.110.0030.00622.25
8.2.100.0070.00318.16
8.2.90.0130.00618.96
8.2.80.0040.00417.97
8.2.70.0040.00417.63
8.2.60.0090.00017.68
8.2.50.0040.00718.07
8.2.40.0040.00420.07
8.2.30.0070.00018.13
8.2.20.0000.00817.71
8.2.10.0070.00018.01
8.2.00.0050.00218.15
8.1.270.0080.00020.39
8.1.260.0140.00326.35
8.1.250.0000.00828.09
8.1.240.0080.00023.83
8.1.230.0080.00419.09
8.1.220.0090.00017.74
8.1.210.0030.00518.77
8.1.200.0060.00317.48
8.1.190.0000.00817.00
8.1.180.0060.00318.10
8.1.170.0040.00418.43
8.1.160.0040.00421.91
8.1.150.0040.00418.85
8.1.140.0050.00517.37
8.1.130.0000.00917.75
8.1.120.0030.00517.54
8.1.110.0040.00417.50
8.1.100.0000.00717.55
8.1.90.0000.00817.47
8.1.80.0040.00417.48
8.1.70.0090.00017.48
8.1.60.0000.00917.64
8.1.50.0000.00917.43
8.1.40.0000.00817.48
8.1.30.0030.00517.68
8.1.20.0060.00317.61
8.1.10.0070.00017.58
8.1.00.0000.00717.41
8.0.300.0000.00818.77
8.0.290.0000.00716.63
8.0.280.0040.00418.52
8.0.270.0040.00417.27
8.0.260.0050.00317.32
8.0.250.0030.00316.98
8.0.240.0070.00016.98
8.0.230.0030.00316.95
8.0.220.0000.00716.89
8.0.210.0040.00416.89
8.0.200.0030.00316.95
8.0.190.0030.00616.97
8.0.180.0000.00816.84
8.0.170.0080.00016.93
8.0.160.0040.00416.96
8.0.150.0070.00016.85
8.0.140.0040.00416.78
8.0.130.0090.00013.34
8.0.120.0030.00616.87
8.0.110.0050.00316.79
8.0.100.0040.00416.84
8.0.90.0070.00316.97
8.0.80.0160.00016.85
8.0.70.0000.00716.92
8.0.60.0040.00416.97
8.0.50.0000.00716.77
8.0.30.0070.01317.08
8.0.20.0130.01617.40
8.0.10.0050.00317.00
8.0.00.0080.01116.64
7.4.330.0050.00015.03
7.4.320.0000.00616.54
7.4.300.0030.00316.60
7.4.290.0070.00016.57
7.4.280.0040.00416.52
7.4.270.0000.00716.63
7.4.260.0070.00016.50
7.4.250.0000.00716.58
7.4.240.0040.00316.59
7.4.230.0030.00316.55
7.4.220.0130.01316.53
7.4.210.0080.00816.63
7.4.200.0040.00416.56
7.4.160.0060.00916.59
7.4.150.0090.00917.40
7.4.140.0120.01417.86
7.4.130.0070.01216.59
7.4.120.0110.00616.43
7.4.110.0090.00916.42
7.4.100.0130.00616.52
7.4.90.0130.00416.36
7.4.80.0090.00919.39
7.4.70.0110.00716.34
7.4.60.0100.00616.52
7.4.50.0000.00416.33
7.4.40.0140.00316.29
7.4.30.0140.00716.63
7.4.00.0000.01714.95
7.3.330.0030.00613.20
7.3.320.0000.00513.21
7.3.310.0030.00316.29
7.3.300.0040.00416.35
7.3.290.0120.00616.39
7.3.280.0080.01016.39
7.3.270.0110.00617.40
7.3.260.0110.00516.36
7.3.250.0080.01016.48
7.3.240.0140.00316.66
7.3.230.0140.00816.65
7.3.210.0060.01016.47
7.3.200.0060.01219.39
7.3.190.0070.01016.36
7.3.180.0090.00616.68
7.3.170.0090.01216.38
7.3.160.0120.00316.67
7.2.330.0120.01216.57
7.2.320.0140.00616.72
7.2.310.0130.00316.49
7.2.300.0140.00316.63
7.2.290.0100.01016.80
7.2.60.0030.01017.04
7.2.00.0070.00719.48
7.1.200.0120.00315.61
7.1.100.0040.00818.29
7.1.70.0020.00517.20
7.1.60.0070.01619.86
7.1.50.0100.01316.93
7.1.00.0070.07322.30
7.0.200.0100.00315.02
7.0.60.0030.08319.93
7.0.50.0070.08317.90
7.0.40.0170.07720.11
7.0.30.0130.05020.23
7.0.20.0270.07320.22
7.0.10.0030.04320.11
7.0.00.0030.08020.07
5.6.280.0000.07721.11
5.6.210.0100.07720.77
5.6.200.0170.07718.20
5.6.190.0070.05720.52
5.6.180.0370.06720.46
5.6.170.0300.06720.47
5.6.160.0070.05720.57
5.6.150.0070.07018.24
5.6.140.0070.08018.18
5.6.130.0100.04718.23
5.6.120.0070.05021.03
5.6.110.0000.04321.02
5.6.100.0000.07020.90
5.6.90.0030.05720.99
5.6.80.0100.04320.37
5.5.350.0370.07020.41
5.5.340.0100.04018.09
5.5.330.0130.03320.42
5.5.320.0330.07320.35
5.5.310.0270.08020.32
5.5.300.0070.03717.98
5.5.290.0030.06017.93
5.5.280.0100.04320.86
5.5.270.0070.04020.88
5.5.260.0070.06020.86
5.5.250.0100.07020.63
5.5.240.0100.06720.27
5.4.450.0070.07719.55
5.4.440.0030.05019.49
5.4.430.0070.07319.64
5.4.420.0030.08319.59
5.4.410.0070.05719.07
5.4.400.0170.03719.32
5.4.390.0030.04718.95
5.4.380.0030.05718.94
5.4.370.0000.04319.23
5.4.360.0000.04019.33
5.4.350.0000.03718.86
5.4.340.0000.03718.95
5.4.320.0100.03019.20
5.4.310.0070.03319.16
5.4.300.0000.03719.14
5.4.290.0000.04019.13
5.4.280.0070.06719.21
5.4.270.0000.03719.08
5.4.260.0070.03319.16
5.4.250.0030.03319.10
5.4.240.0000.03719.09
5.4.230.0000.03719.30
5.4.220.0030.03719.30
5.4.210.0030.03319.21
5.4.200.0000.03719.13
5.4.190.0030.03318.84
5.4.180.0000.04019.30
5.4.170.0000.03719.18
5.4.160.0000.03718.85
5.4.150.0030.03318.97
5.4.140.0030.04716.57
5.4.130.0000.04016.43
5.4.120.0000.04016.39
5.4.110.0070.03316.33
5.4.100.0030.04016.45
5.4.90.0030.03716.57
5.4.80.0000.05016.58
5.4.70.0070.06716.62
5.4.60.0030.05716.56
5.4.50.0030.06716.26
5.4.40.0000.06716.50
5.4.30.0030.07316.42
5.4.20.0100.06016.51
5.4.10.0070.06716.51
5.4.00.0000.05015.76
5.3.290.0000.04014.59
5.3.280.0030.03314.52
5.3.270.0000.03714.52
5.3.260.0000.03714.59
5.3.250.0030.03314.64
5.3.240.0030.03314.64
5.3.230.0000.03714.73
5.3.220.0000.05314.56
5.3.210.0000.03714.55
5.3.200.0000.04714.50
5.3.190.0000.04014.59
5.3.180.0030.06014.57
5.3.170.0000.07014.66
5.3.160.0070.07014.55
5.3.150.0030.07314.63
5.3.140.0030.06314.79
5.3.130.0030.06714.68
5.3.120.0070.07714.48
5.3.110.0030.07014.54
5.3.100.0070.05013.95
5.3.90.0030.06314.04
5.3.80.0100.06714.19
5.3.70.0100.06714.25
5.3.60.0030.04014.17
5.3.50.0030.03713.96
5.3.40.0070.05714.05
5.3.30.0070.06013.85
5.3.20.0000.07313.71
5.3.10.0030.07313.89
5.3.00.0000.07713.66
5.2.170.0030.05712.52
5.2.160.0030.06012.52
5.2.150.0000.05712.52
5.2.140.0030.06012.52
5.2.130.0000.05312.52
5.2.120.0030.05712.52
5.2.110.0000.06312.52
5.2.100.0030.03312.52
5.2.90.0100.04012.52
5.2.80.0030.06012.52
5.2.70.0000.03712.52
5.2.60.0000.03712.52
5.2.50.0000.05312.52
5.2.40.0030.05712.52
5.2.30.0000.03312.52
5.2.20.0070.04012.52
5.2.10.0100.05712.52
5.2.00.0000.06012.52
5.1.60.0070.04312.52
5.1.50.0030.05012.52
5.1.40.0030.05012.52
5.1.30.0070.04312.52
5.1.20.0030.03312.52
5.1.10.0000.04312.52
5.1.00.0000.05712.52
5.0.50.0030.04712.52
5.0.40.0000.04712.52
5.0.30.0030.06312.52
5.0.20.0070.02712.52
5.0.10.0070.04012.52
5.0.00.0000.06312.52
4.4.90.0030.02312.52
4.4.80.0030.02312.52
4.4.70.0000.02312.52
4.4.60.0030.02312.52
4.4.50.0030.02012.52
4.4.40.0000.04012.52
4.4.30.0000.03712.52
4.4.20.0000.02712.52
4.4.10.0000.04012.52
4.4.00.0030.03312.52
4.3.110.0130.02012.52
4.3.100.0000.02712.52
4.3.90.0100.03012.52
4.3.80.0030.04312.52
4.3.70.0000.03012.52
4.3.60.0000.03312.52
4.3.50.0000.03712.52
4.3.40.0130.03712.52
4.3.30.0030.01712.52
4.3.20.0000.03012.52
4.3.10.0000.03312.52
4.3.00.0070.03012.52

preferences:
39.6 ms | 400 KiB | 5 Q