Utilising the power of uksort
(although happy to be directed elsewhere if necessary), I'm looking at implementing a custom sort routine to sort, in ascending order, an array based on its key.
The problem I'm having is the key is a string, but I'd like to treat the key as an int (in two parts). My array is as follows:
[20-2 => object, 20-1 => object, 4-1 => object, 3-1 => object]
What I would like to do is order primarily by the int value of the first half of the key, then the second half (where there are multiple entries that share the first half). For instance, I would like to order to the following:
[3-1 => object, 4-1 => object, 20-1 => object, 20-2 => object]
Thanks
Tried ksort
, but because my keys are strings it pretty much did nothing
Edit: I do NOT have access to the creation of the array in order to change the keys into something more easily sortable. I am using PHP7