Performance wise you're better off looping through arrays like you're doing than traversing dataobjectsets. Arrays are generally much faster than object iterators. I've also read that recursive functions are slow in PHP but I don't have anything to back that up with so don't take my word for it.
you know, I thought it you wanted it to keep going recursively...
As I understand it (although I could be badly wrong here) doing a foreach on a dataobjectset invokes it's ->toArray() method and then it iterates over that... besides I optimize when it's required in the 1% of cases in the 99% I prefer succinct readable code.
I agree with you Swaiba on performance vs readability but I do want to add that (at least for me) recursive functions are seldom readable in an easy fashion. Your function is very short so that one's easy to read but at least in my experience recursive functions often get messy pretty fast. The reason I wrote about performance was simply because Dendeffe asked about it.
For the foreach I think it's using the iterator interface defined in the class and thus each foreach calls one of those methods. Those methods do work directly with the internal array but I do think you still get the overhead of calling the object methods. But like Swaiba said in 99% of the cases this shouldn't be the overhead in your application so it isn't really something to worry about unless you're working with huge data sets.