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"; }

preferences:
23.44 ms | 407 KiB | 5 Q