3v4l.org

run code in 300+ PHP versions simultaneously
<?php function treeifyDbRows(array $inputArray, array $branchRules): array { $output = []; if ($branchRules) { $ruleSet = array_shift($branchRules); $masterRule = $ruleSet[0]; $branchChildren = []; foreach ($inputArray as $index => $element) { $branchChildren[] = $element; //coalesce null to 0 if (($inputArray[$index + 1][$masterRule] ?? 0) !== $element[$masterRule]) { $branch = []; foreach ($ruleSet as $rule) { $branch[$rule] = $branchChildren[0][$rule]; } $children = treeifyDbRows($branchChildren, $branchRules); if ($children) { $branch['children'] = $children; } $output[] = $branch; $branchChildren = []; } } } return $output; } $data = [ [ "countryID" => 1, "countryName" => "USA", "regionID" => 10, "regionName" => "Indiana", "cityID" => 100, "cityName"=> "Indianapolis", ], [ "countryID" => 1, "countryName" => "USA", "regionID" => 10, "regionName" => "Indiana", "cityID" => 101, "cityName"=> "Bloomington", ], [ "countryID" => 1, "countryName" => "USA", "regionID" => 11, "regionName" => "Michigan", "cityID" => 102, "cityName"=> "Lansing", ], [ "countryID" => 2, "countryName" => "Canada", "regionID" => 12, "regionName" => "Ontario", "cityID" => 103, "cityName"=> "Toronto", ], [ "countryID" => 2, "countryName" => "Canada", "regionID" => 12, "regionName" => "Ontario", "cityID" => 104, "cityName"=> "Ottawa", ], [ "countryID" => 2, "countryName" => "Canada", "regionID" => 12, "regionName" => "Ontario", "cityID" => 105, "cityName"=> "Windsor", ], [ "countryID" => 2, "countryName" => "Canada", "regionID" => 25, "regionName" => "Quebec", "cityID" => 106, "cityName"=> "Montreal", ], ]; $rules = [ ["countryID", "countryName"], ["regionID", "regionName"], ["cityID", "cityName"], ]; $results = treeifyDbRows($data, $rules); var_dump($results);

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.0000.02118.54
8.3.50.0040.01220.18
8.3.40.0150.00420.47
8.3.30.0100.00618.89
8.3.20.0000.00824.18
8.3.10.0070.00324.66
8.3.00.0040.00426.16
8.2.180.0150.00325.92
8.2.170.0120.00322.96
8.2.160.0100.00722.96
8.2.150.0040.00425.66
8.2.140.0030.00624.66
8.2.130.0080.00026.16
8.2.120.0050.00319.83
8.2.110.0060.00322.16
8.2.100.0080.00419.64
8.2.90.0080.00017.75
8.2.80.0040.00418.92
8.2.70.0000.00818.16
8.2.60.0040.00417.59
8.2.50.0030.00517.55
8.2.40.0040.00419.28
8.2.30.0000.00818.05
8.2.20.0050.00220.38
8.2.10.0070.00018.00
8.2.00.0000.00719.30
8.1.280.0090.00625.92
8.1.270.0000.00824.66
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0090.00023.79
8.1.230.0110.00019.14
8.1.220.0040.00417.76
8.1.210.0000.00918.77
8.1.200.0040.00417.35
8.1.190.0070.00717.13
8.1.180.0080.00018.10
8.1.170.0040.00418.99
8.1.160.0050.00518.86
8.1.150.0060.00318.74
8.1.140.0040.00417.37
8.1.130.0000.00819.03
8.1.120.0000.00817.38
8.1.110.0020.00517.47
8.1.100.0000.00817.37
8.1.90.0050.00317.38
8.1.80.0070.00417.33
8.1.70.0110.00017.44
8.1.60.0070.00417.55
8.1.50.0060.00617.46
8.1.40.0080.00317.53
8.1.30.0120.00017.44
8.1.20.0150.00317.61
8.1.10.0050.00817.55
8.1.00.0120.00317.50
8.0.300.0060.00618.77
8.0.290.0040.00416.63
8.0.280.0000.00818.36
8.0.270.0030.00516.82
8.0.260.0050.00318.45
8.0.250.0080.00016.95
8.0.240.0000.00816.93
8.0.230.0080.00017.01
8.0.220.0070.00716.82
8.0.210.0100.00516.93
8.0.200.0100.00516.93
8.0.190.0060.00916.94
8.0.180.0000.01516.84
8.0.170.0130.00216.89
8.0.160.0040.01116.75
8.0.150.0070.00716.79
8.0.140.0120.00316.86
8.0.130.0100.00516.66
8.0.120.0090.00616.88
8.0.110.0060.00916.77
8.0.100.0100.00716.90
8.0.90.0160.00016.79
8.0.80.0060.00916.74
8.0.70.0130.00316.79
8.0.60.0110.00416.82
8.0.50.0080.00816.82
8.0.30.0120.00316.79
8.0.20.0080.00816.97
8.0.10.0150.00016.90
7.4.330.0000.00515.55
7.4.320.0030.00316.60
7.4.300.0000.00816.61
7.4.290.0070.00416.46
7.4.280.0110.00416.56
7.4.270.0140.00416.48
7.4.260.0110.00616.64
7.4.250.0080.00416.49
7.4.240.0140.00416.59
7.4.230.0060.01016.61
7.4.220.0120.00316.53
7.4.210.0050.01016.48
7.4.200.0110.00616.40
7.4.190.0110.00616.63
7.4.180.0120.00316.68
7.4.160.0140.00016.55
7.4.150.0070.00716.62
7.4.140.0110.00316.47
7.4.130.0120.00316.45
7.4.120.0150.00016.59
7.4.110.0130.00016.43
7.4.100.0110.00016.45
7.4.90.0120.00016.50
7.4.80.0070.00416.39
7.4.70.0040.00416.46
7.4.60.0110.00016.44
7.4.50.0100.00516.36
7.4.40.0090.00016.45
7.4.30.0000.01016.45
7.4.20.0040.00416.46
7.4.10.0070.00316.39
7.4.00.0030.00716.54

preferences:
52.92 ms | 401 KiB | 5 Q