What is a Function in PHP?
PHP functions are a great way to break code down into modular and reusable chunks. Functions may come from the standard PHP distribution or additional extensions compiled with PHP, or they may be custom created by developers for specific projects.
A function in PHP is simply an expression that returns a value. It works like a variable and can take in information through arguments. The argument is placed after the function name in parentheses and can be one or many expressions.
Information can also be passed into a function by reference. This makes the function work on a copy of the variable instead of the actual value in memory. This is important because it means that the value inside the function will not change outside of the function.
A function can return a number or an array of values. It can also return a list of objects, or an object array. Lastly, a function can call other functions, which is called a function chain or a closure. This allows for recursion, which is useful for looping through large numbers of items. For example, a while loop might use an array to store the number of times it has passed through an item in a list.