In this function that I use to search some element in a tree ,how can I stop the recursion when I found the seached element?
public function find($element, $found_path){
var_dump($element->getName());
if($element->getAbsolute_path() == $found_path){
$this->current = &$element;
} else {
if(isset($element->descendants)){
foreach($element->descendants as $descendant){
$this->find($descendant, $found_path);
}
}
}
}
The search is correct, but the complete tree is visited. I need to stop when the searched element is found.