3.4. Building Functions

Functions are the key to reusability. You have already learned to call PHP's built-in functions in this chapter but up to now you have not implemented your own functions. In this section you will learn to build your own PHP functions.

3.4.1. Simple Functions

Let's start with a simple example: Gauss's Formula for the sum of integers.

Johann Carl Friedrich Gauss was born on April 30, 1777, in Brunswick, Germany. At the age of seven, Carl Friedrich Gauss started elementary school, and his potential was noticed almost immediately. His teacher, Büttner, and his assistant, Martin Bartels, were amazed when Gauss summed the integers from 1 to 100 instantly by spotting that the sum was 50 pairs of numbers each pair summing to 101. ...

Get PHP and PostgreSQL: Advanced Web Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.