How can a function be designed to accept an unknown number of arguments in PHP?

To create a function that accepts an unknown number of arguments in PHP, you can use the func_get_args() function within the function definition. This function returns an array containing all the arguments passed to the function. You can then iterate over this array to process each argument accordingly.

function sum() {
    $args = func_get_args();
    $total = 0;
    
    foreach($args as $arg) {
        $total += $arg;
    }
    
    return $total;
}

echo sum(1, 2, 3, 4); // Output: 10