peterhuynh Posted February 14, 2015 Share Posted February 14, 2015 Hi, supernoob here. This is my 2nd thread. The 1st one was very helpful. I want to sort a multidimensional array. I have something like this: {"bids": [[ 100, 24 ], [ 300, 10 ], [ 200, 34 ]], "asks": [[ 300, 23 ], [ 100, 34 ], [ 200, 21]]} I want to order "bids" such that the largest first number in the square brackets goes first. (I realize I'm not explaining this well.) For example, I want "[[ 300, 10 ], [ 200, 34 ], [ 100, 24 ]]". And I want to order "asks" such that the smallest first number in the square bracket goes first. For example, I want "[[ 100, 34 ], [ 200, 21 ], [ 300, 23]]" Thank you so much! Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted February 14, 2015 Solution Share Posted February 14, 2015 try $arr = json_decode('{"bids": [[ 100, 24 ], [ 300, 10 ], [ 200, 34 ]], "asks": [[ 300, 23 ], [ 100, 34 ], [ 200, 21]]}', 1); rsort($arr['bids']); sort($arr['asks']); echo '<pre>',print_r($arr, true),'</pre>'; 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.