calling a function within a function [solved]

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
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

calling a function within a function [solved]

Post by php3ch0 »

How can I do this or is it not possible?

Code: Select all

function dosomething() {
     echo "something";
}

function dosomethingelse() {
    dosomething();
}
Last edited by php3ch0 on Tue Dec 04, 2007 7:24 am, edited 1 time in total.
User avatar
Jaxolotl
Forum Contributor
Posts: 137
Joined: Mon Nov 13, 2006 4:19 am
Location: Argentina and Italy

Post by Jaxolotl »

of course it is possible and a common way to combine functions. Remember to pray attention to the availability of the variable you will use (unless you pass them or you set them as global inside the function, the variables will be only locally available if declared/assigned inside the function)

http://php.net/manual/en/language.functions.php
User avatar
webspider
Forum Commoner
Posts: 52
Joined: Sat Oct 27, 2007 3:29 am

Post by webspider »

Are you talking about recursion function?
User avatar
Jaxolotl
Forum Contributor
Posts: 137
Joined: Mon Nov 13, 2006 4:19 am
Location: Argentina and Italy

Post by Jaxolotl »

webspider wrote:Are you talking about recursion function?
The example written by php3ch0 seems a "scope" question. I mean, calling a foreign function inside another function. Recursion would be calling the function inside itself.
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

yes it was calling a foreign function in another function.
Thanks worked a treat.
User avatar
webspider
Forum Commoner
Posts: 52
Joined: Sat Oct 27, 2007 3:29 am

Post by webspider »

yes I missed the "else" :)

Code: Select all

function dosomethingelse() 
{
  dosomething();
}
It was just calling a function from a function.
Post Reply