Here is a PHP function that will take a string as input and return an array with the last two elements as separate elements, and the rest of the elements combined into one element.

function splitString($input) {
    $words = explode(" ", $input);
    $lastTwo = array_slice($words, -2);
    $combined = implode(" ", array_slice($words, 0, -2));
    return [$combined, ...$lastTwo];
}

// Example usage:
$input = "abc d aa an 3";
$result = splitString($input);
print_r($result);

Output:

Array
(
    [0] => abc d aa
    [1] => an
    [2] => 3
)
``
make php function for me input abc d aa an 3 return abc d aaan3 ONLY put last 2 elements sole elemnet

原文地址: https://www.cveoy.top/t/topic/iqMo 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录