3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ 'Stack Over Flow Abcpqr (UR)', 'Fluency in English Conversation Defklmno (1WIR)', 'English Proficiency GHI (2WIR)', 'Testing ADG (3WIR)', ]; function implodeNotLastTwoElements($string) { $array = explode(' ', $string); return [implode(' ', array_slice($array, 0, -2))] + array_slice($array, -3); } foreach ($strings as $string) { echo json_encode(implodeNotLastTwoElements($string)) . "\n"; }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
["Stack Over Flow","Abcpqr","(UR)"] ["Fluency in English Conversation","Defklmno","(1WIR)"] ["English Proficiency","GHI","(2WIR)"] ["Testing","ADG","(3WIR)"]

preferences:
335.76 ms | 407 KiB | 5 Q