Is it advisable to use optional parameters in PHP functions for better code maintenance?
Using optional parameters in PHP functions can be useful for better code maintenance as it allows for more flexibility in function calls without needing to create multiple function variations. This can make the code more readable and easier to maintain in the long run.
function greet($name, $greeting = "Hello") {
echo $greeting . ", " . $name;
}
greet("John"); // Output: Hello, John
greet("Jane", "Hi"); // Output: Hi, Jane