I'm not sure if I understand this perfectly, but wouldn't array_merge be enough? From what I can make out, it looks like you don't want to merge in duplicates, but I don't see why that is a problem.