Jump to content

calling/returning a function inside of another function?


zeeshan_haider000

Recommended Posts

Hi,

Is it possible to call a function that is inside another function?

something like:

function parent(){

  function child($param){

  $a = $param+.......;

  return $a;

        } //child function

 

echo '......';

som more code.....

} //Parent function closed.

 

So when the child function is called, only the value $a is returned without executing the parent function....

Like: $b = child();

        echo $b; //$a is echoed

 

Is this possible, if yes, how do you do it?

Zee

child() only exists within parent() so no, its not plausible. Why on earth would you need said functionality?

 

I am trying to create a cache system, and i need the said functionality to check if the contents are changed or not with a query....

Will this work instead?

function parent($what){

if ($what = 'child function'){

  function child($param){

  $a = $param+.......;

  return(or if return doesnt work, then i guess echo) $a;

  exit()

        } //child function

else{

parent function

  }

}//parent function closed

 

what i am trying to do is that i have a meta tag with the the number of rows from db as its content, and i am trying to compare it using the above function, by getting the number of rows and compare it with the one in the file.... the child function must inside of the parent function because parent function is important to what i am doing, as it does everything...

Uh I get your explanation, but I don't get why that involves a child function.

 

lol i will just modify the parent function then, you are right no need for child function, wanted to make thing simpler for later use but made it more confusing....

 

EDIT:

Dang it, i forgot i can't do that, as there is some code that must be executed after only which the child function/code should be executed.... like parent function{ condition... do this.. if this == condition.. then do this.. and then do child()... hmm

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.