Functions in PHP

Copying the same code you need to every location you need it in is neither practical nor efficient. In the latest installment for learning PHP, you learn how to build functions as well as how to use the built-in functions provided.

provided by: 
Originally published at Internet.com


A complete PHP application might contain upwards of dozens of individual script files, with hundreds of lines of code in each. Between all of those, there will be many instances where the same piece of code is reused: something as simple as outputting a string to the browser or as complex as making sure a user is logged in across multiple pages, and prompting them for login information if they are not.

As you might imagine, copying the same code you need to every location you need it in is neither practical nor efficient.

Fortunately PHP, like most other programming languages, includes a language structure called a Function. A Function is a self-contained code block that performs a specific job. In most cases, they accept input from the main script as arguments, and return some kind of result. They can help modularize a script by allowing the programmer to break the script down by task. They are also portable, so if you write a useful function for one script, you can easily reuse it in another.

In this article, we will be covering some introductory information on functions. We will also be taking a brief look at PHP's pre-defined functions before focusing on creating and using your own...

Read article at Internet.com site

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML