php - Call a function within a function display both within array -


how call function within function?

function tt($data,$s,$t){     $data=$data;     echo '[[';     print_r($data);     echo ']]';     if($t==0){         $data[]=$s;         tt($data,'two',1);     }else{         $data[]=$s;     }     return $data; } print_r(tt('','one',0)); 

i want 'two' shown within array like

$o[]='one'; $o[]='two'; print_r($o); 

function tt($s, $t, array $data = array()) {     $data[] = $s;     if ($t == 0) {         $data = tt('two', 1, $data);     }     return $data; }  print_r(tt('one', 0)); 

this that's needed.

  1. put array last argument , make optional, because don't need on initial call.
  2. when calling tt recursively, need "catch" return data, otherwise recursive call nothing of lasting value.
  3. no need else, since you're going append entry array no matter , don't need write twice.

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -