Jump to content


Photo

Function withn a function


  • Please log in to reply
1 reply to this topic

#1 alecjw

alecjw
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationHatfield, Herts, UK

Posted 07 August 2006 - 04:34 PM

Could you use a function within a function eg:

<?php
function a()
{
//Some code
}
function b()
{
a()
//Some code
}
?>

Or would you need to make function a() global first?

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 August 2006 - 04:40 PM

Yes you can call a function within a function. However if you have a function defined within a function you first have to call the function that has the embeded function. Then you can call the emebed function. Like so:
// define the function within a function
function foo() {
    function bar() {
        echo "foobar";
    }
}

//call foo first
foo();

// now you can use bar function
bar();





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users