Reverse the order of a multiple-elements array in PHP -


this question has answer here:

i looked quite bit around (like here array-sort-comparisons), , tried figure out how sort (or reverse) multiple-elements array. in vain.

i have 3 elements in array, , want sort "year" asc:

array(52) {   [0]=>   array(3) {     ["id"]=>     string(2) "si"     ["year"]=>     string(4) "2012"     ["value"]=>     string(7) "3711339"   }   [1]=>   array(3) {     ["id"]=>     string(2) "si"     ["year"]=>     string(4) "2011"     ["value"]=>     string(7) "3810626"   }   [2]=>   array(3) {     ["id"]=>     string(2) "si"     ["year"]=>     string(4) "2010"     ["value"]=>     string(7) "3714946"   } 

how possible? somehow 1 needs able specify of 3 elements "key" basis of sorting.

thanks hints!

use usort() custom comparison function:

usort($arr, function (array $a, array $b) {     return $a['year'] - $b['year']; }); 

demo


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -