Function
From DocForge
A function is a named subroutine, or block of code. Functions can be called one or more times from other executing blocks of code. They usually have their own internal scope, meaning variables and other named blocks of code can be created locally and not referenced from outside the function.
Many third-generation programming languages implement functions in some form. This generally improves a programming language's readability and aids in developing modularly.
Contents |
[edit] Parameters
Most programming languages which support functions allow those functions to receive parameters. Parameters are passed either by reference or by value into locally scoped function variables.
[edit] Pass By Reference
Parameters passed by reference retain a reference (often a memory location) to the original variable defined outside the function. Changes to the local parameter are therefore automatically made to the original variable outside the function.
[edit] Pass By Value
Parameters passed by value are copies of the original variables set in the function call. Changes to the parameter are not reflected in the original variable outside the function. The new parameter value is lost when the function execution ends.
By default, PHP, up to version 4, passes parameters by value.
[edit] Recursion
A recursive function is one which calls itself. They're often used where nested execution is required, such as maze solving and tree searches.