• Functions provide the core of PHP's programming functionality, and there are hundreds to choose from.

  • However, the chances are you are only going to use about twenty or so in common practice, so don't waste time trying to learn them all - that' what the manual is there for!

  • Writing your own functions eliminates code duplication, thereby reducing the likelihood of bugs, and making it easier for you to make changes to the code.

  • Passing by and returning by reference can often make your script more efficient, however it is important to note that objects are inherently passed by reference.

  • PHP's string manipulation functions are very powerful and very flexible, although it is worth your while always trying to use the least complicated function suitable for your purpose - don't bother with regexes when a simpler function will do.

  • Recursive functions are useful for a wide variety of tasks, whether it be printing a threaded messageboard index or path-finding in a game.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Exercises >>

Previous chapter: Undocumented functions

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.