Concept

How can related PHP functions be organized?

ComputerScienceOne / Organizing Functions

"40.1.2. Organizing Functions There are many coding standards that guide how PHP code should be organized. We’ll only discuss a simple mechanism here. One way to organize functions is to collect functions with similar functionality into separate PHP source files. Suppose the functions above are in a PHP source file named utils.php. We could include them in another source file (our “main” source file) using an include_once function invocation. An example:\n\n1 <?php\n\n2\n\n3 include_once(\"utils.php\");\n\n4\n\n5 //we can now use the functions in utils.php:\n\n6 $p = getMonthlyPayment(1000, 0.05, 12);\n\n7\n\n8 ?>\n\nThe include_once function loads and evaluates the given PHP source file at the point in the code in which it is invoked. The “once” in the function refers to the fact that if the source file was already included in the script/code before, it will not be included a second time. This allows you to include the same source file in multiple source files without a conflict."

Related Ideas

How can related PHP functions be organized? | ComputerScienceOne | Bifalgorithm | Bifalgorithm