Returning Multiple Values Create calcWeightResults Return statement can only return one variable Call totalOz If you need a function to return multiple values, use Calcs both endLbs and parameters endOz Use two PBR output function funcName(&$parm1, &$parm2) parameters Function changes memory location (variable) passed to it instead of making its own copy Call from cases file & instructs PHP to treat parameters as pass by reference (instead of pass by value) & represents the of the variable address Inside the function, you don’t include the & in variable name (only in the parameter) Also don’t include in call Alternatively, could use global variables Global Variables Use globals Any variable declared outside a function is considered a global variable All the variables we’ve used so far are global They are available in all PHP tags throughout a page, except in functions Any variable declared in a function is local to the function A function may access a global variable. The function must that it is using a global variable declare global $varName; This example assumes the variable is $varName declared outside the function, but not in another function (in the global PHP code)
Returning Multiple Values Return statement can only return one variable If you need a function to return multiple values, use parameters function funcName(&$parm1, &$parm2) Function changes memory location (variable) passed to it instead of making its own copy & instructs PHP to treat parameters as pass by reference (instead of pass by value) & represents the address of the variable Inside the function, you don’t include the & in variable name (only in the parameter) Also don’t include in call Alternatively, could use global variables Create calcWeightResults Call totalOz Calcs both endLbs and endOz Use two PBR output parameters Call from cases file Global Variables Any variable declared outside a function is considered a global variable All the variables we’ve used so far are global They are available in all PHP tags throughout a page, except in functions Any variable declared in a function is local to the function A function may access a global variable. The function must declare that it is using a global variable global $varName; This example assumes the variable $varName is declared outside the function, but not in another function (in the global PHP code) Use globals
Unit%204%20-%20Functions%20and%20Include%20Files.docx