O'Reilly logo

PHP 5 Recipes: A Problem-Solution Approach by Jon Stephens, Frank M. Kromann, Nathan A. Good, Lee Babin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 11Using Functions

Redundant code is rarely a good thing. Rewriting code over and over again is not time efficient and looks rather shoddy from a layout point of view. Like any good programming language, PHP alleviates the problem of redundant code in a number of ways; the most commonly used and simple-to-implement way is by using functions.

A function is basically a block of code that performs a given action from the script that has access to it, via includes, code insertions, or other methods. Rather than repeatedly rewrite the same block of code to, say, check if the current user is logged into your site, you can put the code into what is essentially a code wrapper and then call it at your convenience with a simple function call.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required