PHP 버전
4+
$products = [
    '사과' => 3000,
    '바나나' => 1000,
    '체리' => 5000
];

// 값 기준 오름차순으로 정렬
asort($products);

// 결과 출력
print_r($products);
출력
$countries = [
    'US' => 'United States',
    'KR' => 'Korea',
    'JP' => 'Japan',
    'FR' => 'France',
    'AU' => 'Australia'
];

// 국가명 기준 오름차순으로 정렬
asort($countries);

// 결과 출력
print_r($countries);
출력
// PHP 8.2.0 전
asort(array &$array, int $flags = SORT_REGULAR): true

// PHP 8.2.0부터
asort(array &$array, int $flags = SORT_REGULAR): bool
$items = [
    'a' => 12,
    'b' => 'abc',
    'c' => '15',
    'd' => 7,
    'e' => 'Banana'
];

// 숫자 기준 정렬 (SORT_NUMERIC)
// 배열의 모든 값(value)을 숫자로 간주하여 오름차순 정렬
// 숫자로 변환할 수 없는 문자열('abc', 'Banana')은 0으로 취급되어 정렬 시 앞쪽에 위치
$items = [
    'a' => 12,
    'b' => 'abc',
    'c' => '15',
    'd' => 7,
    'e' => 'Banana'
];
asort($items, SORT_NUMERIC);
var_dump($items);
/*
array(5) {
  ["b"]=> string(3) "abc"      // 숫자로 변환 불가 → 0 취급 → 오름차순에서 가장 앞
  ["e"]=> string(6) "Banana"   // 숫자로 변환 불가 → 0 취급 → 그 다음
  ["d"]=> int(7)               // 숫자 7
  ["a"]=> int(12)              // 숫자 12
  ["c"]=> string(2) "15"       // 문자열 '15'는 숫자 15로 간주 → 맨 뒤
}
*/

$items = [
    'a' => 12,
    'b' => 'abc',
    'c' => '15',
    'd' => 7,
    'e' => 'Banana'
];

// 문자열 기준 정렬 (SORT_STRING)
// 배열의 모든 값(value)을 문자열로 간주하여 사전식(lexicographical) 오름차순 정렬
$items = [
    'a' => 12,
    'b' => 'abc',
    'c' => '15',
    'd' => 7,
    'e' => 'Banana'
];
asort($items, SORT_STRING);
var_dump($items);
/*
array(5) {
  ["a"]=> int(12)              // '12' 문자열로 변환 → 사전식 비교
  ["c"]=> string(2) "15"       // '15'
  ["d"]=> int(7)               // '7'
  ["e"]=> string(6) "Banana"   // 'Banana'
  ["b"]=> string(3) "abc"      // 'abc'
}
*/