1.

How To Specify Argument Default Values?

Answer»

If you want to ALLOW the caller to skip an argument when calling a function, you can define the argument with a default VALUE when defining the function. Adding a default value to an argument can be done like this "function name($arg=expression){}. Here is a PHP script on how to specify default values to ARGUMENTS:
<?php
function printKey($KEY="download") {
print("PHP $key\n");
}
printKey();
printKey("hosting");
print("\n");
?>
This script will print:
PHP download
PHP hosting

If you want to allow the caller to skip an argument when calling a function, you can define the argument with a default value when defining the function. Adding a default value to an argument can be done like this "function name($arg=expression){}. Here is a PHP script on how to specify default values to arguments:
<?php
function printKey($key="download") {
print("PHP $key\n");
}
printKey();
printKey("hosting");
print("\n");
?>
This script will print:
PHP download
PHP hosting



Discussion

No Comment Found