tHud Posted July 19, 2014 Share Posted July 19, 2014 Hello, I've been struggling to get array_multisort to work... If I have this array output... I'd like to sort on the product sub-array. The array is called orders and that number 15 is the specific order id. Array ( [15] => Array ( [clientId] => 1 [clientName] => Bob [o_date] => 2014-01-02 [o_number] => 1 july-append [o_notes] => order on 1 july-append [i_date] => 2014-01-17 [i_number] => 18072014-append [i_notes] => invoiced on 18 july 14 -append [products] => Array ( [0] => Array ( [id] => 37 [prod_id] => 1 [product] => door [qty] => 2 [cost] => 12.121 ) [1] => Array ( [id] => 38 [prod_id] => 2 [product] => window [qty] => 3 [cost] => 22.5 ) [2] => Array ( [id] => 36 [prod_id] => 3 [product] => chair [qty] => 1 [cost] => 300 ) ) ) ) So, I've tried a number of variations of this... array_multisort($orders[$theOrder]['products'], SORT_DESC, SORT_NUMERIC, $orders[$theOrder]['products'], SORT_ASC, SORT_STRING); array_multisort($orders[$theOrder]['products']['id'], SORT_DESC, SORT_NUMERIC); etc. etc. - but I seem to get no-where. Can some-one kindly point out my error, please? Thank you. :) Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted July 19, 2014 Solution Share Posted July 19, 2014 I'd like to sort on the product sub-array. On which field? You could use uasort() with a custom sort function, but the best way to do is when you you get the data from the database in the first place (if that is where the array came from originally) Quote Link to comment Share on other sites More sharing options...
tHud Posted July 19, 2014 Author Share Posted July 19, 2014 Thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.