docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화

Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고,
Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
This commit is contained in:
Antigravity Agent
2026-07-05 00:10:59 +09:00
parent a397bc4720
commit 1cfd3bbb56
1495 changed files with 68534 additions and 27 deletions
@@ -0,0 +1,75 @@
---
id: php-looping-foreach
title: "PHP Looping Foreach"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["foreach loop", "byref", "PHP foreach 반복문"]
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", "loops", "foreach", "arrays"]
raw_sources: ["https://www.w3schools.com/php/php_looping_foreach.asp"]
applied_in: []
github_commit: ""
---
# [[PHP Looping Foreach]]
## 🎯 한 줄 통찰 (One-line insight)
By default, modifying the loop variable inside `foreach` does NOT affect the original array — but adding a single `&` (`foreach ($colors as &$x)`) switches to by-reference assignment, meaning changes to `$x` inside the loop DO mutate `$colors` directly, a one-character difference with a completely different mutation contract. [S1]
## 🧠 핵심 개념 (Core concepts)
- **`foreach ($array as $value)`** — loops over indexed array values. [S1]
- **`foreach ($array as $key => $value)`** — loops over associative arrays, exposing both key and value. [S1]
- **Works on objects too** — iterates over public properties (`$name => $value`). [S1]
- **By-value default** — modifying the loop variable does not change the source array. [S1]
- **By-reference (`&$x`)** — modifying the loop variable DOES change the source array. [S1]
- **`break`** / **`continue`** — same semantics as other loops. [S1]
- **Alternative syntax** — `foreach (...) : ... endforeach;`. [S1]
## 📖 세부 내용 (Details)
- Indexed array: `$colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; }`. [S1]
- Associative array: `$members = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); foreach ($members as $key => $value) { echo "$key : $value <br>"; }`. [S1]
- Object properties: `foreach ($myCar as $x => $y) { echo "$x: $y <br>"; }`. [S1]
- By-value (no mutation): `foreach ($colors as $x) { if ($x == "blue") $x = "pink"; } // $colors unchanged`. [S1]
- By-reference (mutates original): `foreach ($colors as &$x) { if ($x == "blue") $x = "pink"; } // $colors now has "pink" instead of "blue"`. [S1]
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **참조 전달의 예외적 동작**: 기본적으로 반복 변수 수정은 원본 배열에 영향을 주지 않지만, &를 붙이면 원본이 실제로 변경된다는 점이 두 예제로 명확히 대비됨. [S1]
## 🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — 배열 값을 순회하며 특정 조건에 따라 원본을 직접 수정해야 할 때 &$x 참조 전달이 사용된다. [S1]
## 💻 코드 패턴 (Code patterns)
By-reference foreach mutates the original array (PHP):
```php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as &$x) {
if ($x == "blue") $x = "pink";
}
var_dump($colors); // "blue" is now "pink" in the original array
```
## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.90
- **중복 검사 결과:** 신규 생성 (New discovery)
## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[PHP Tutorial]]
- **관련 개념:** [[PHP Looping For]], [[PHP Arrays]], [[PHP OOP Classes Objects]]
- **참조 맥락:** 배열/객체 순회 전용 반복문 — break/continue 챕터로 이어짐.
## 📚 출처 (Sources)
- [S1] W3Schools — PHP foreach Loop — https://www.w3schools.com/php/php_looping_foreach.asp
## 📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "PHP foreach Loop" page (Astra wiki-curation, P-Reinforce v3.1 format).