Hello. You must sort the array in descending order using a specific key.

Code:

$result = array(); $i = 0; foreach($result as $value) { $result[$i]['example'] = $value; } $data = array(); foreach($result as $key => $value) { $data[$key] = $value['example']; } array_multisort($data, SORT_DESC, SORT_NUMERIC, $result); 

But, the fact is that it sorts by 1 or 2 digits, that is:

There are numbers: 9, 927, 99, 97. In sorted form it will look like this: 99, 97, 927, 9.

  • @evansive, what is the data type under the key 'example'? And it would be good to show part of the original array. - Deonis
  • If you are only expecting integers, try this $ data [$ key] = intval ($ value ['example']); The $result array, judging by your code, generally remains empty. By the way, what do you want to achieve with these metamorphoses? foreach ($ row as $ value) {$ row [$ i] ['example'] = $ value; } - Johny

1 answer 1

And what is not suitable for you built rsort () and arsort () ?

According to the Documentation (it is possible in Russian ), the first is able to sort the arrays in reverse order, the second is the same, but at the same time it keeps the keys (in an associative array, of course)