How to define and use functions within functions in PHP

3 Answers

0 votes
function f_out() 
{
  function f_in() 
  {
    echo "need to call f_out() first.";
  }
}

f_in();


/*
run:

Fatal error: Call to undefined function f_in() 
in C:\xampp\htdocs\webshopy.com\test.php on line 11

*/

 



answered Jun 20, 2016 by avibootz
0 votes
function f_out() 
{
  function f_in() 
  {
    echo "need to call f_out() first.";
  }
}

f_out();
f_in();


/*
run:

need to call f_out() first.

*/

 



answered Jun 20, 2016 by avibootz
0 votes
function f_out() 
{
  function f_in() 
  {
    echo "need to call f_out() first.";
  }
}

f_out(); // will not call f_in()


/*
run:



*/

 



answered Jun 20, 2016 by avibootz

Related questions

...