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
- How can PHP developers handle the issue of expired download links for users who face interruptions during the download process?
- What are best practices for handling HTTP requests in PHP to prevent unintended multiple executions of functions?
- What potential security risks are associated with using $_SERVER['PHP_SELF'] in PHP scripts?