Tiny performance improvement !
Another performance improvement. Take out in_array looping.
Add optional $collapsedParams to regular getQueryParams for the case when you only want to collapse a few.