3v4l.org

run code in 300+ PHP versions simultaneously
<?php // The first group to assign un-prefixed items to $firstGroup = 'MAKE'; // Every possible word grouping $wordList = ['ENGINE', 'MODEL', 'POWER', 'TORQUE', 'GEAR', 'DRIVE', 'YEAR']; // Test string $string = 'Audi MODEL 80 ENGINE 1.9 TDi POWER 90Hk TORQUE 202Nm GEAR man DRIVE 2wd YEAR 1996'; // Key/value of group name and values $groups = []; // Default to the first group $currentWord = $firstGroup; foreach (explode(' ', $string) as $word) { // Found a special word, reset and continue the hunt if (in_array($word, $wordList)) { $currentWord = $word; continue; } // Assign. The subsequent for loop could be removed by just doing string concatenation here instead $groups[$currentWord][] = $word; } // Optional, join each back into a string foreach ($groups as $key => $values) { $groups[$key] = implode(' ', $values); } var_dump($groups);

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.120.0140.00622.15
8.4.110.0100.00920.55
8.4.100.0040.00518.43
8.4.90.0130.00818.51
8.4.80.0060.00319.48
8.4.70.0070.01318.15
8.4.60.0050.00318.79
8.4.50.0120.00818.73
8.4.40.0130.00620.32
8.4.30.0060.01120.75
8.4.20.0030.01719.55
8.4.10.0040.00422.23
8.3.250.0070.01118.99
8.3.240.0120.00716.54
8.3.230.0080.01216.71
8.3.220.0030.00517.27
8.3.210.0030.00516.87
8.3.200.0060.00416.73
8.3.190.0100.00916.71
8.3.180.0070.00218.66
8.3.170.0060.01218.69
8.3.160.0060.01320.13
8.3.150.0100.01016.60
8.3.140.0080.00018.93
8.3.130.0040.00418.37
8.3.120.0060.00319.14
8.3.110.0090.00018.36
8.3.100.0040.00418.50
8.3.90.0040.00426.77
8.3.80.0030.00617.97
8.3.70.0110.00716.50
8.3.60.0040.01118.30
8.3.50.0100.00718.35
8.3.40.0140.00320.52
8.3.30.0110.00418.65
8.3.20.0100.00324.18
8.3.10.0050.00224.66
8.3.00.0080.00026.16
8.2.290.0140.00520.38
8.2.280.0110.00918.37
8.2.270.0180.00018.82
8.2.260.0040.00418.54
8.2.250.0040.00416.56
8.2.240.0090.00017.32
8.2.230.0040.00420.94
8.2.220.0040.00424.06
8.2.210.0040.00426.77
8.2.200.0000.01018.88
8.2.190.0120.00316.58
8.2.180.0110.00416.50
8.2.170.0040.01122.96
8.2.160.0070.00722.96
8.2.150.0080.00025.66
8.2.140.0000.00824.66
8.2.130.0050.00326.16
8.2.120.0100.00018.79
8.2.110.0060.00322.25
8.2.100.0110.00017.72
8.2.90.0000.00817.75
8.2.80.0080.00018.78
8.2.70.0040.00417.63
8.2.60.0060.00317.93
8.2.50.0030.00518.07
8.2.40.0000.00818.28
8.2.30.0000.00818.07
8.2.20.0150.00517.74
8.2.10.0070.00717.86
8.2.00.0120.00017.68
8.1.330.0120.00321.78
8.1.320.0100.00818.58
8.1.310.0110.00718.47
8.1.300.0040.00418.01
8.1.290.0040.00430.84
8.1.280.0150.00625.92
8.1.270.0040.00424.66
8.1.260.0000.00826.35
8.1.250.0070.00028.09
8.1.240.0000.00920.83
8.1.230.0060.00617.89
8.1.220.0030.00617.78
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0000.00917.36
8.1.180.0080.00018.10
8.1.170.0080.00018.64
8.1.160.0030.00518.77
8.1.150.0080.00417.49
8.1.140.0080.00317.46
8.1.130.0110.00017.46
8.1.120.0040.00717.42
8.1.110.0080.00817.43
8.1.100.0160.00017.44
8.1.90.0110.00417.43
8.1.80.0070.00717.57
8.1.70.0130.00317.48
8.1.60.0180.00017.71
8.1.50.0120.00617.46
8.1.40.0100.00517.63
8.1.30.0080.00517.27
8.1.20.0110.00017.61
8.1.10.0160.00017.48
8.1.00.0070.00717.38
8.0.300.0050.00318.77
8.0.290.0000.00816.75
8.0.280.0030.00318.36
8.0.270.0110.00516.80
8.0.260.0120.00316.79
8.0.250.0150.00016.79
8.0.240.0100.00516.88
8.0.230.0150.00016.88
8.0.220.0150.00016.77
8.0.210.0020.00916.82
8.0.200.0100.00316.70
8.0.190.0110.00216.88
8.0.180.0120.00417.01
8.0.170.0150.00016.79
8.0.160.0030.00916.82
8.0.150.0100.00516.74
8.0.140.0050.01016.82
8.0.130.0120.00416.83
8.0.120.0120.00216.82
8.0.110.0060.00916.85
8.0.100.0000.01116.71
8.0.90.0050.00916.79
8.0.80.0140.00016.80
8.0.70.0100.00316.81
8.0.60.0130.00016.70
8.0.50.0070.00716.69
8.0.30.0070.00716.76
8.0.20.0060.00616.79
8.0.10.0000.01316.95

preferences:
32.52 ms | 403 KiB | 5 Q