---
id: php-arrays-sort
title: "PHP Arrays Sort"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["sort", "ksort", "asort", "PHP 배열 정렬"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.9
created_at: 2026-07-04
updated_at: 2026-07-04
review_reason: ""
merge_history: []
tags: ["php", "programming", "w3schools", "arrays", "sorting"]
raw_sources: ["https://www.w3schools.com/php/php_arrays_sort.asp"]
applied_in: []
github_commit: ""
---

# [[PHP Arrays Sort]]

## 🎯 한 줄 통찰 (One-line insight)
Sorting an associative array requires choosing whether to sort by KEY or by VALUE as two entirely separate function families — `asort()`/`arsort()` sort by value while `ksort()`/`krsort()` sort by key, meaning "sort this associative array" is an ambiguous request in PHP that must be resolved to one of four specific functions. [S1]

## 🧠 핵심 개념 (Core concepts)
- **`sort()`** — indexed array, ascending. [S1]
- **`rsort()`** — indexed array, descending. [S1]
- **`asort()`** — associative array, ascending BY VALUE. [S1]
- **`ksort()`** — associative array, ascending BY KEY. [S1]
- **`arsort()`** — associative array, descending BY VALUE. [S1]
- **`krsort()`** — associative array, descending BY KEY. [S1]

## 📖 세부 내용 (Details)
- sort (strings): `$cars = array("Volvo", "BMW", "Toyota"); sort($cars); print_r($cars); // alphabetical`. [S1]
- sort (numbers): `$numbers = array(4, 6, 2, 22, 11); sort($numbers); // ascending numeric`. [S1]
- rsort: `rsort($cars); // descending alphabetical`. [S1]
- asort (by value): `$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); asort($age); // sorted by age value, ascending`. [S1]
- ksort (by key): `ksort($age); // sorted by name key, alphabetically ascending`. [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **키 정렬 vs 값 정렬의 명확한 분리**: 연관 배열 정렬은 값 기준(asort/arsort)과 키 기준(ksort/krsort)이 완전히 다른 함수로 분리되어 있다는 점이 강조됨. [S1]

## 🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — 나이순으로 사람 목록을 정렬(asort)하거나 이름순으로 정렬(ksort)하는 것이 실전 활용의 대표 사례다. [S1]

## 💻 코드 패턴 (Code patterns)
Sorting an associative array by value vs. by key (PHP):
```php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
asort($age);  // sort by value (age), ascending
ksort($age);  // sort by key (name), ascending
```

## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.90
- **중복 검사 결과:** 신규 생성 (New discovery)

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[PHP Tutorial]]
- **관련 개념:** [[PHP Arrays Remove]], [[PHP Arrays Multidimensional]], [[PHP Arrays Functions]]
- **참조 맥락:** 배열 정렬 함수 6종 — 다차원 배열(Multidimensional) 챕터로 이어짐.

## 📚 출처 (Sources)
- [S1] W3Schools — PHP Sorting Arrays — https://www.w3schools.com/php/php_arrays_sort.asp

## 📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "PHP Sorting Arrays" page (Astra wiki-curation, P-Reinforce v3.1 format).
