How can optional arguments be handled within PHP functions?

Optional arguments in PHP functions can be handled by assigning default values to the parameters in the function declaration. This allows the function to be called with fewer arguments than specified, with the default values being used for any missing arguments. By setting default values for certain parameters, you can make those parameters optional when calling the function.

function greet($name, $message = "Hello") {
    echo $message . ", " . $name;
}

greet("John"); // Output: Hello, John
greet("Alice", "Hi"); // Output: Hi, Alice