0

i need to recursively call a variable function, how can i do this?

$rec = function($li) use($html,$rec) { // error, rec was not defined yet
   if( ... ) $rec( ... ); 
}

how can i do this?

Richard
  • 56,349
  • 34
  • 180
  • 251
Kokizzu
  • 24,974
  • 37
  • 137
  • 233

1 Answers1

2

Use the function variable $rec by reference (&$rec) so you can set it to the function then. This will also define it.

use($html, &$rec) 
           ^

You find this principle outlined in the question Anonymous recursive PHP functions.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836