--- id: php-switch title: "PHP Switch" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["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", "switch"] raw_sources: ["https://www.w3schools.com/php/php_switch.asp"] applied_in: [] github_commit: "" --- # [[PHP Switch]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Omitting `break` causes "fall-through" that runs the NEXT case's code too, regardless of whether it matches β€” the source's own example demonstrates this directly: removing `break` from the matched "red" case makes the "blue" case's code execute right after it, even though `$favcolor` is definitely not "blue". [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`switch(expression)`** β€” evaluates once, compares against each `case`. [S1] - **`break`** β€” required to stop fall-through into the next case; the LAST case doesn't strictly need it. [S1] - **Fall-through warning** β€” omitting break in a non-last case runs the next case's code unconditionally. [S1] - **`default`** β€” runs when no case matches. [S1] - **Combining cases** β€” stacking multiple `case` labels with no code between them shares one code block. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic switch: `switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": ...; default: ...; }`. [S1] - Fall-through demonstration: removing `break` from `case "red":` causes `case "blue":`'s code to also run even though favcolor is "red", not "blue". [S1] - Combined cases: `case 1: case 2: case 3: case 4: case 5: echo "The week feels so long!"; break; case 6: case 0: echo "Weekends are best!"; break;`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **break μƒλž΅ μ‹œ 폴슀루(fall-through) κ²½κ³ **: λ§ˆμ§€λ§‰μ΄ μ•„λ‹Œ caseμ—μ„œ breakλ₯Ό μƒλž΅ν•˜λ©΄ λ‹€μŒ case μ½”λ“œκ°€ 맀치 여뢀와 λ¬΄κ΄€ν•˜κ²Œ μ‹€ν–‰λœλ‹€λŠ” 점이 예제둜 직접 증λͺ…됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” μš”μΌ κ·Έλ£Ή(평일/주말)을 case κ²°ν•©μœΌλ‘œ ν‘œν˜„ν•˜λŠ” 것이 μ‹€μ „ ν™œμš©μ˜ λŒ€ν‘œ νŒ¨ν„΄μ΄λ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Combining multiple case labels for shared logic (PHP): ```php $d = 3; switch ($d) { case 1: case 2: case 3: case 4: case 5: echo "The week feels so long!"; break; case 6: case 0: echo "Weekends are best!"; break; default: echo "Something went wrong"; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP If Nested]], [[PHP Match]], [[PHP Looping]] - **μ°Έμ‘° λ§₯락:** 닀쀑 λΆ„κΈ° ꡬ쑰 β€” Match ν‘œν˜„μ‹(PHP 8) μ±•ν„°λ‘œ 직접 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP switch Statement β€” https://www.w3schools.com/php/php_switch.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP switch Statement" page (Astra wiki-curation, P-Reinforce v3.1 format).