I have this recursive function up and running:
function my_function($a, $b, $level=0){
$items = get_some_items($a, $b);
$fh = fopen($fpath, 'a+');
foreach($items as $item){
fwrite($fh, "Some info related to $item");
if( /* $item has something special */ ){
my_function($a, $item, $level++);
}
}
if( /* we a re at the last recursion */ ){
//do something extra special;
//e.g. fwrite($fh, "This is the end of the file");
}
fclose($fh);
}
With this, I can tell which iteration is the first run. I can also get the nth run at any level.
My question: I'd like to do something special during the very last run. Is there even a way to neatly achieve this?