function using 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
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

function using itself

Post by m2babaey »

Hi
can i use a function this way:

Code: Select all

 
function determinant($mtrix, $n){
 
if ($n=1) {
// do something
}
else
{
return aclcaulationssss*determinant($mtrix, $n-1);
}
}
 
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: function using itself

Post by onion2k »

Yes. It's called recursion. Be careful you don't write something that can end up in an infinite loop.
Post Reply