Counting and categorizing items in an array

@alex.newpath what is “IMTKEY”. @Callinetic used it in this response - i assumed it was to do with the headers but now you have used it as well. (no rush to respond).