php_mysql_apache [Electronic resources]

Julie C. Meloni

نسخه متنی -صفحه : 323/ 69
نمايش فراداده

What Is a Function?

You can think of a function as a machine. A machine takes the raw materials you feed it and works with them to achieve a purpose or to produce a product. A function accepts values from you, processes them, and then performs an action (printing to the browser, for example), returns a new value, or both.

If you needed to bake a single cake, you would probably do it yourself. If you needed to bake thousands of cakes, you would probably build or acquire a cake-baking machine. Similarly, when deciding whether to create a function, the most important factor to consider is the extent to which it can save you from writing repetitive code.

A

function is a self-contained block of code that can be called by your scripts. When called, the function's code is executed. You can pass values to a function, which will then use them appropriately. When finished, a function can pass a value back to the calling code.