PHP usort function multiple criteria sorting

201 views Asked by At

Hello I have a multidimensional array and the last "nested array" holds one more level of arrays. I want to sort all the arrays in this level by 2 keys 1. "Enabled" - (int value - DESC) 2. "Order" - (int value - ASC)

I have a working function that only sorts by the "order" key but I want it to check for the "Enabled" key as well.

Here's what I currently have:

         function sorter($item1,$item2)
        {
            if($item1['order'] == $item2['order']) return 0;
            return ($item1['order'] > $item2['order']) ? -1 : 1;
        }
         uasort($array['level1']['level2']['level3'],'sorter');

Can someone help me out? Thanks in advance :)

0

There are 0 answers