PHP 버전
4+
$numbers = [4, 2, 8, 1, 5];
rsort($numbers); // 배열 자체를 직접 수정
print_r($numbers);
출력 정렬된 순으로 배열의 키(인덱스)를 재설정
$names = ['Charlie', 'Alice', 'Bob', 'David'];
rsort($names); // 배열 자체를 직접 수정
print_r($names);
출력 정렬된 순으로 배열의 키(인덱스)를 재설정
// PHP 8.2.0 전
rsort(array &$array, int $flags = SORT_REGULAR): true

// PHP 8.2.0부터
rsort(array &$array, int $flags = SORT_REGULAR): bool
$items = [12, 'abc', '15', 7, 'Banana'];

// 숫자 기준 내림차순 정렬 (SORT_NUMERIC)
// 배열의 모든 항목을 숫자로 간주하여 내림차순 정렬
// 숫자로 변환할 수 없는 문자열('abc', 'Banana')은 0으로 취급되어 정렬 시 뒤쪽에 위치
$items = [12, 'abc', '15', 7, 'Banana'];
rsort($items, SORT_NUMERIC);
var_dump($items);
/*
array(5) {
  [0]=> string(2) "15"       // 숫자 15
  [1]=> int(12)              // 숫자 12
  [2]=> int(7)               // 숫자 7
  [3]=> string(3) "abc"      // 숫자로 변환 불가 → 0 취급 → 뒤쪽
  [4]=> string(6) "Banana"   // 숫자로 변환 불가 → 0 취급 → 맨 뒤
}
*/

$items = [12, 'abc', '15', 7, 'Banana'];

// 문자열 기준 내림차순 정렬 (SORT_STRING)
// 배열의 모든 항목을 문자열로 간주하여 사전식(lexicographical) 내림차순 정렬
// 숫자(int)도 비교할 때 문자열로 변환
$items = [12, 'abc', '15', 7, 'Banana'];
rsort($items, SORT_STRING);
var_dump($items);
/*
array(5) {
  [0]=> string(3) "abc"      // 사전식 내림차순 → 가장 뒤쪽 알파벳이 먼저
  [1]=> string(6) "Banana"
  [2]=> int(7)               // 숫자 7 → 문자열 '7'로 비교
  [3]=> string(2) "15"       // 문자열 '15'
  [4]=> int(12)              // 숫자 12 → 문자열 '12'로 비교
}
*/