How can you modify a PHP function to make a parameter optional and not mandatory?
To make a parameter optional in a PHP function, you can assign a default value to the parameter in the function definition. This way, if the parameter is not provided when calling the function, it will use the default value instead. This allows for more flexibility in function usage without requiring all parameters to be provided.
function exampleFunction($param1, $param2 = 'default') {
// Function code here
}
Keywords
Related Questions
- Are there any specific PHP functions or methods that can be used to handle error messages in a login form more efficiently?
- In what situations would it be more efficient to let the database handle grouping data instead of PHP?
- What are the potential pitfalls of using a database field to track user login status in PHP?