Optional Parameters Create calcDeliveryDate with optional time Normal parameters are required parameter (default + 2 If a parameter is optional, the function call does not need wks). to include it (though it may) To define an optional parameter, you include it in the Use REQUEST element parameter list but also assign it a default value function showAddress($addr, $city, $state='WI') Test with no parameter. Test with parameter. When calling this function, the call must include an address and city, but the state is optional. If it is not included, WI is used. Examples: showAddress('123 Main St', 'New York', 'NY'); showAddress('933 Michigan Ave', 'Stevens Point'); If some parameters are required and others are optional (like the example above), the optional parameters must come last in the parameter list A required parameter could not be included zip code after the optional parameter in the example state above. Variable Parameter Lists FYI Only Some functions accept a variable number of parameters These parameters differ from optional parameters No parameters are listed in the function declaration All parameters are optional You can force the call to include one parameter, but including a parameter in the ( ) Inside the function you can list a list of the values sent to the function: $parms = func_get_args(); is a in PHP function func_get_args Creates an array of values sent to the function
Optional Parameters Normal parameters are required If a parameter is optional, the function call does not need to include it (though it may) To define an optional parameter, you include it in the parameter list but also assign it a default value function showAddress($addr, $city, $state='WI') When calling this function, the call must include an address and city, but the state is optional. If it is not included, WI is used. Examples: showAddress('123 Main St', 'New York', 'NY'); showAddress('933 Michigan Ave', 'Stevens Point'); If some parameters are required and others are optional (like the example above), the optional parameters must come last in the parameter list A required zip code parameter could not be included after the optional state parameter in the example above. Create calcDeliveryDate with optional time parameter (default + 2 wks). Use REQUEST element Test with no parameter. Test with parameter. Variable Parameter Lists Some functions accept a variable number of parameters These parameters differ from optional parameters No parameters are listed in the function declaration All parameters are optional You can force the call to include one parameter, but including a parameter in the ( ) Inside the function you can list a list of the values sent to the function: $parms = func_get_args(); func_get_args is a in PHP function Creates an array of values sent to the function FYI Only
Unit%204%20-%20Functions%20and%20Include%20Files.docx