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
  • 50,293
  • 28
  • 163
  • 235
Kokizzu
  • 22,630
  • 29
  • 120
  • 213

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
  • 184,866
  • 48
  • 414
  • 792