Can a function call itself?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Rincewind
Forum Commoner
Posts: 27
Joined: Thu Nov 21, 2002 11:15 am
Location: Norway

Can a function call itself?

Post by Rincewind »

I'm trying to make a message-board (much like this one) and I'm clear on how I'm gonna list messages in the main window, also messages have a parent-id in the database, discerning what message it is an answer to, and each message has an int in the database telling how many childen-messages it has.

My problem is that a childen-message can have children and children of children of children...
So how do I loop through them to get them to list correctly below the right message?
One possible sollution is having a function listing 1 message with input message-id, then calling itself subsequently when it lists a message with a child...is this doable?
Can a function call itself??

Thanx

Rincewind_the_Wizzard
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

It's called "recursion" or a "recursive function call."

I just did a search on the term in the PHP manual and did not find it, so I can't tell you whether PHP allows it or not. Some languages do (i.e. C/C++), some do not.

Why don't you just give it a try and see what happens?
Rincewind
Forum Commoner
Posts: 27
Joined: Thu Nov 21, 2002 11:15 am
Location: Norway

Just did...

Post by Rincewind »

As a matter of fact that was my reason for coming here now, to say: Nevermind, it works...
So php allows it apparently :)
I was trying it, just didn't get it to work, so I posted here to find out if I was working at an impossible angle, but I was just being stupid, works now....

Thanx anyway :)
Post Reply