?– Tip You can browse PHP??™s massive function list by visiting the official PHP site at http://
www.php.net/ and perusing the documentation. There you??™ll find not only definitions and examples
for each function broken down by library, but reader comments pertinent to their usage. If you know
the function name beforehand, you can go directly to the function??™s page by appending the function
name onto the end of the URL. For example, if you want to learn more about the pow() function, go
to http://www.php.net/pow.
CHAPTER 4 ?– FUNCTIONS 115
Creating a Function
Although PHP??™s vast assortment of function libraries is a tremendous benefit to anybody
seeking to avoid reinventing the programmatic wheel, sooner or later you??™ll need to
go beyond what is offered in the standard distribution, which means you??™ll need to
create custom functions or even entire function libraries. To do so, you??™ll need to
define a function using a predefined template, like so:
function functionName(parameters)
{
function-body
}
For example, consider the following function, generateFooter(), which outputs a
page footer:
function generateFooter()
{
echo "Copyright 2007 W. Jason Gilmore";
}
Once defined, you can call this function like so:
generateFooter();
?>
This yields the following result:
Copyright 2007 W. Jason Gilmore
Passing Arguments by Value
You??™ll often find it useful to pass data into a function.
Pages:
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199