Functions

Imagine designing a car. You would want to design the engine and the body together because you have to know that they fit each other. If you had a design team working for you, this team would work on and coordinate ideas for both the engine and the body. But now think about the CD player that will go into this car. Because it requires a totally different design technique and poses completely different design problems, it calls for an entirely different type of design team. A car design team would put together the car, leaving a standard sized hole in the dashboard with a few wires ready for the CD player when it was completed. A CD player design team would construct the CD so that it would fit the hole and match the wiring in the car when it was completed.

You can do the same with functions in PHP. Pick parts of your program that stand alone and put those parts in functions. You can farm out the function development work to others and reduce development time by reusing the functions in other programs. When industrial superhero, the Australian Jacques Nassar was promoted to head of Ford Motor Company's world wide operations, Jacques replaces 22 cigarette lighter designs with one design manufactured in 3 sizes. Jacques Nassar is now CEO of Ford. Just think where you could go with brilliant reuse of code.

This chapter not only explains functions and describes good uses for them but also walks you through the process of learning how to apply them on your own.

Chapter 10 Functions contains the following sections:
   In Depth
      The World's Shortest Function
      Returning Values
      Supplying Values
      Optional Values
      Variable Number of Input Fields
      Scope
      Static Variables
      Recursion
      Functions Named in Variables
      Sequence
   Immediate Solutions
      Creating a Function
      Declaring a Global Variable
      Declaring a Static Variable
      Storing a Function in a Variable
      Using Default Function Parameters
      Checking that a Function Exists
      Using call_user_func()
      Using create_function()
      Using func_get_arg() and func_num_args()
      Using func_get_args()
      Registering a Shutdown Function