How can PHP handle default parameter values based on conditions?

In PHP, default parameter values can be set based on conditions by using a ternary operator within the function definition. The ternary operator allows us to check a condition and set the default value accordingly. This approach can be useful when you want to have different default values based on certain conditions.

function exampleFunction($param1, $param2 = null) {
    $default = ($param1 == 'condition') ? 'default_value1' : 'default_value2';
    $param2 = ($param2 === null) ? $default : $param2;
    
    // Rest of the function code here
}