Detect recursion in arrays