How can PHP beginners ensure they are using optional parameters correctly in their code?

PHP beginners can ensure they are using optional parameters correctly by setting default values for those parameters in the function definition. This way, if the optional parameter is not provided when calling the function, it will default to the specified value. This ensures that the code will not break if the optional parameter is omitted.

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

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