Call function within a function PHP?

Define the function above your return value, otherwise it never gets executed.

It doesn't work as you are calling bar() before it has been created. See example 2 here:- php.net/manual/en/functions.user-defined....

If you define function within another function, it can be accessed directly, but after calling parent function. For example: function a () { function b() { echo "I am b. "; } echo "I am a."; } //b(); Fatal error: Call to undefined function b() in E:\..\func.

Php on line 8 a(); // Print I am a. B(); // Print I am b.

Execution not execute after return statement change your code like this function foo($i){ function bar($i){ return $i*4; } return bar($i)*4; } echo foo(4).

Your code never reach function bar(...), therefore it's never defined. You need to put your bar() function before your foo() or before the return bar. (Answer based on your first example).

With your second example you probably define bar() before you use foo() therefore bar() is defined and it works fine. So as long as you have your function defined when you hit a certain spot in your code it works fine, no matter if it's called from within another function.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions