How does the use of func_get_args() or func_get_arg() help in handling functions with multiple parameters in PHP?

When dealing with functions that have a variable number of parameters, using func_get_args() or func_get_arg() allows you to handle these parameters dynamically without explicitly defining them in the function definition. This can be useful when you want to create flexible functions that can accept different numbers of arguments without needing to modify the function signature each time.

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

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