3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ 0 => 'Business Services', 1 => 'Business Services_Consulting', 2 => 'Business Services_Foodservice Distribution', 3 => 'Business Services_Information Services', 4 => 'Consumer', 5 => 'Consumer_Consumer Discretionary', 6 => 'Consumer_Consumer Discretionary_Apparel, Footwear & Accessories', 7 => 'Consumer_Consumer Discretionary_Apparel, Footwear & Accessories_Activewear', 8 => 'Consumer_Consumer Discretionary_Apparel, Footwear & Accessories_Apparel', 9 => 'Consumer_Consumer Discretionary_Apparel, Footwear & Accessories_Footwear', ]; // Our output array $array = []; foreach ($data as $item) { // Store a reference to the "deepest" item (so far) $last = &$array; // Split on known delim and iterate over foreach (explode('_', $item) as $key) { // See next comment for what this does. if (!is_array($last)) { $last = []; } // Set a key to match the value exactly. If the value has "child" objects, the logic // above will take care of removing the value and replacing it with an array. if (!array_key_exists($key, $last)) { $last[$key] = $key; } // Reset our "deepest" item $last = &$last[$key]; } } echo json_encode($array, JSON_PRETTY_PRINT);

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.4.140.0130.00917.59
8.4.130.0110.00717.60
8.4.120.0110.00922.54
8.4.110.0120.00820.61
8.4.100.0130.00718.72
8.4.90.0100.01120.46
8.4.80.0100.00918.86
8.4.70.0130.00818.76
8.4.60.0130.00720.49
8.4.50.0090.01117.82
8.4.40.0110.00819.35
8.4.30.0030.00618.88
8.4.20.0110.01118.99
8.4.10.0060.00317.70
8.3.270.0110.00816.72
8.3.260.0120.00816.48
8.3.250.0140.00519.11
8.3.240.0100.00916.69
8.3.230.0120.00716.59
8.3.220.0090.00319.04
8.3.210.0100.00216.86
8.3.200.0040.00616.88
8.3.190.0120.00716.64
8.3.180.0090.01017.19
8.3.170.0130.00616.59
8.3.160.0040.00419.87
8.3.150.0090.00916.54
8.3.140.0050.00317.13
8.3.130.0080.00018.26
8.3.120.0040.00420.68
8.3.110.0110.00816.62
8.3.100.0050.00316.78
8.3.90.0030.00526.77
8.3.80.0030.00718.43
8.3.70.0080.00818.55
8.3.60.0070.00716.50
8.3.50.0100.01016.34
8.3.40.0090.00618.52
8.3.30.0140.00018.79
8.3.20.0040.00424.18
8.3.10.0000.00724.66
8.3.00.0000.00826.16
8.2.290.0030.00520.65
8.2.280.0120.01118.29
8.2.270.0180.00019.13
8.2.260.0000.00818.41
8.2.250.0080.00018.88
8.2.240.0110.00717.12
8.2.230.0070.00320.94
8.2.220.0060.00324.06
8.2.210.0160.00326.77
8.2.200.0090.00016.75
8.2.190.0070.00716.58
8.2.180.0100.01025.92
8.2.170.0110.00419.13
8.2.160.0130.00322.96
8.2.150.0040.00425.66
8.2.140.0060.00324.66
8.2.130.0030.00626.16
8.2.120.0040.00426.35
8.2.110.0030.00622.08
8.2.100.0080.00417.78
8.2.90.0000.00720.50
8.2.80.0040.00418.73
8.2.70.0000.00817.61
8.2.60.0060.00319.88
8.2.50.0030.00518.05
8.2.40.0050.00319.77
8.2.30.0000.00818.19
8.2.20.0050.00318.07
8.2.10.0080.00019.38
8.2.00.0000.00719.37
8.1.330.0110.00823.73
8.1.320.0100.01015.98
8.1.310.0040.00418.46
8.1.300.0060.00616.25
8.1.290.0030.00630.84
8.1.280.0140.00725.92
8.1.270.0070.00023.99
8.1.260.0030.00526.35
8.1.250.0040.00428.09
8.1.240.0030.00620.89
8.1.230.0110.00017.89
8.1.220.0060.00317.74
8.1.210.0050.00318.77
8.1.200.0100.00017.35
8.1.190.0000.00817.23
8.1.180.0080.00019.30
8.1.170.0040.00418.57
8.1.160.0000.00719.10
8.1.150.0000.00718.95
8.1.140.0000.00718.90
8.1.130.0030.00320.18
8.1.120.0050.00317.49
8.1.110.0040.00417.47
8.1.100.0000.00817.47
8.1.90.0030.00417.48
8.1.80.0050.00517.53
8.1.70.0070.00017.43
8.1.60.0000.00817.48
8.1.50.0000.00817.52
8.1.40.0080.00017.48
8.1.30.0040.00417.64
8.1.20.0040.00417.66
8.1.10.0030.00717.62
8.1.00.0040.00417.45
8.0.300.0040.00418.77
8.0.290.0060.00316.75
8.0.280.0000.00718.45
8.0.270.0000.00718.08
8.0.260.0000.00618.50
8.0.250.0030.00316.98
8.0.240.0060.00316.95
8.0.230.0030.00316.94
8.0.220.0040.00416.89
8.0.210.0000.00716.89
8.0.200.0070.00417.00
8.0.190.0050.00316.96
8.0.180.0000.00716.93
8.0.170.0030.00716.81
8.0.160.0040.00416.89
8.0.150.0030.00516.86
8.0.140.0080.00016.79
8.0.130.0050.00013.32
8.0.120.0070.00016.89
8.0.110.0000.00816.81
8.0.100.0040.00416.99
8.0.90.0050.00316.74
8.0.80.0080.00916.86
8.0.70.0040.00416.79
8.0.60.0050.00316.80
8.0.50.0040.00416.70
8.0.30.0060.00916.94
8.0.20.0150.01517.00
8.0.10.0150.01217.05
8.0.00.0200.01416.97
7.4.330.0030.00315.55
7.4.320.0000.00616.60
7.4.300.0000.00716.45
7.4.290.0000.00716.35
7.4.280.0030.00516.61
7.4.270.0000.00716.51
7.4.260.0000.00513.29
7.4.250.0040.00416.58
7.4.240.0030.00616.52
7.4.230.0030.00516.71
7.4.220.0040.00416.63
7.4.210.0090.00616.57
7.4.200.0040.00416.54
7.4.160.0060.01116.54
7.4.150.0230.00416.47
7.4.140.0140.01116.54
7.4.130.0180.01416.50
7.4.120.0290.00316.40
7.4.110.0230.00716.50
7.4.100.0170.00916.44
7.4.90.0160.00916.46
7.4.80.0110.01416.52
7.4.70.0140.01016.54
7.4.60.0260.00016.46
7.4.50.0170.00716.57
7.4.40.0140.01116.35
7.4.30.0170.01416.55
7.4.20.0170.00916.45
7.4.10.0220.00916.46
7.4.00.0120.00916.60
7.3.330.0000.00716.18
7.3.320.0000.00613.17
7.3.310.0070.00016.39
7.3.300.0000.00716.29
7.3.290.0060.00816.40
7.3.280.0140.01216.32
7.3.270.0000.02516.31
7.3.260.0220.00416.27
7.3.250.0230.00816.34
7.3.240.0190.01316.29
7.3.230.0190.00616.34
7.3.220.0150.01016.29
7.3.210.0220.00416.25
7.3.200.0150.00916.29
7.3.190.0180.00716.24
7.3.180.0150.00916.29
7.3.170.0220.00416.27
7.3.160.0150.01116.28
7.3.150.0150.00916.29
7.3.140.0170.00716.24
7.3.130.0230.01016.36
7.3.120.0210.00316.25
7.3.110.0200.00516.16
7.3.100.0160.00816.18
7.3.90.0230.00016.53
7.3.80.0180.00716.26
7.3.70.0120.01616.40
7.3.60.0130.01016.42
7.3.50.0220.00316.48
7.3.40.0150.01516.47
7.3.30.0170.00716.43
7.3.20.0100.01416.43
7.3.10.0170.00716.39
7.3.00.0180.00716.32

preferences:
110.52 ms | 403 KiB | 5 Q