How can optional parameters be handled in PHP functions?

Optional parameters in PHP functions can be handled by assigning default values to those parameters. This allows the function to be called without providing a value for the optional parameter, in which case the default value will be used. This provides flexibility and allows for more customizable function calls.

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

greet("Alice"); // Output: Hello, Alice!
greet("Bob", "Good morning"); // Output: Good morning, Bob!