> I thought about that but I wanted the array to persist throughout the life of the script. Otherwise it would be doing a lot of calls to that.

Why? You have the same calls to the membergroups() function. (or, could you show a counter-example?)