HomePHP Developing a Discussion Forum in PHP with Recursion
Developing a Discussion Forum in PHP with Recursion
If you’re interested in learning how to use recursion in PHP, look no further. Welcome to the third (and last) tutorial of the series “Recursion in PHP.” In three parts, this series walks through the fundamentals of recursive functions in PHP, in addition to explaining how to define and utilize recursive methods in object-based applications.
As you'll probably recall, over the previous article I drew the general guidelines for defining and using recursive methods inside PHP classes. Because a method is simply a function that belongs to a particular class in an object-based development environment, creating recursive methods doesn't differ considerably from building regular recursive functions.
Provided that you defined the appropriate logic of a recursive method, all you have to remember is to include the popular "$this->" pointer, followed by the method's name, at the point where the method calls itself. As you can see, this process is really straightforward and easy to grasp.
After covering in detail how to define recursive method and functions, the question is: what comes next? Luckily, there's vast terrain to explore with reference to using recursion in PHP. As I said in previous articles of this series, recursion can be used in cases where a specific tree structure or a linked list needs to be navigated, in order to display, add, delete or edit its values. It's exactly for that reason that this last article will be focused on building an extensible discussion forum, which precisely uses a tree structure (implemented on a single MySQL database table) for displaying forum messages and adding new posts.
Of course, using the core logic of this forum as a starting point, you can experiment by adding more features to the overall application and build a more complex discussion forum. This can be integrated with your existing PHP applications, or eventually added to future ones.
Are you ready to start learning how to build a discussion forum in PHP? Right, let's do it together.