Chapter 5. Reusing Code and Writing Functions
This chapter explains how reusing code leads to more consistent, reliable, maintainable code, with less effort. We demonstrate techniques for modularizing and reusing code, beginning with the simple use of require()
and include()
to use the same code on more than one page. We explain why these includes are superior to server-side includes. The example given here covers using include files to get a consistent look and feel across your site. We also explain how you can write and call your own functions using page and form generation functions as examples.
Key topics covered in this chapter include
Reusing code
Using
require()
andinclude()
Introducing functions
Defining functions
Using parameters
Understanding ...
Get PHP and MySQL Web Development, Third Edition 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.