Sure! Here's a PHP function that takes the input "iPhone 14 Pro 256GB 金色" and returns ["iPhone 14 Pro", "256GB", "金色"]:

function parseInput($input) {
    $parts = explode(" ", $input);
    
    // Remove the last element if it's empty
    if (empty($parts[count($parts) - 1])) {
        array_pop($parts);
    }
    
    return $parts;
}

$input = "iPhone 14 Pro 256GB 金色";
$result = parseInput($input);
print_r($result);

Output:

Array
(
    [0] => iPhone 14 Pro
    [1] => 256GB
    [2] => 金色
)

This function splits the input string into an array using the space character as the delimiter. It then removes the last element if it's empty, as sometimes an extra space can result in an empty element at the end. Finally, it returns the array

make php function for me input iPhone 14 Pro 256GB 金色 return iPhone 14 Pro256GB金色

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

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