I've humbled over your very useful solution (Thank you!) and I may suggest to you, that you can indicate the sortorder by using negative/positive values within the sortkeys array. For example, if there is an twodimensional array with 4 columns, the user may give the parameter like array(3,-2,1), which means that the columns 3 and 1 will be ascending sorted and column 2 will be descending. I've done this before in a completely different case, but I thought it might be a nice way to solve this.
Unfortunately I couldn't figure out, where in your code you iterate through the columns, so I can't make a code example (I'm non professional, just learning by doing).
Excuse my English, best regards from good old germany,