Reignfire Posted May 12, 2014 Share Posted May 12, 2014 Hi, This is the output from a var_dump($array); command: array (size=381) 0 => array (size=2) 'Name' => string 'apple' (length=6) 'Number' => float 0.368844763 1 => array (size=2) 'Name' => string 'Blueberry' (length= 'Number' => float 5.59E-6 2 => array (size=2) 'Name' => string 'Cinnamon' (length=5) 'Number' => float -0.0006947 3 => array (size=2) 'Name' => string 'Date' (length=10) 'Number' => float 0.001584453 ... ... ... I want to sort this array from the highest 'Number' float value to the smallest. I tried sorting it with rsort($array,SORT_NUMERIC); but that doesn't give the correct output. What kind of 'sort' should i use to do this? Quote Link to comment https://forums.phpfreaks.com/topic/288435-sort-float-values-from-array/ Share on other sites More sharing options...
mac_gyver Posted May 12, 2014 Share Posted May 12, 2014 the most straightforward method would be to use usort() - http://us3.php.net/usort and write a function that compares the 'Number' elements of the arrays. another method would be to use array_multisort() Quote Link to comment https://forums.phpfreaks.com/topic/288435-sort-float-values-from-array/#findComment-1479184 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.