--- id: php-if-else-if title: "PHP If Else If" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["elseif", "PHP if-else-if"] 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", "conditions", "elseif"] raw_sources: ["https://www.w3schools.com/php/php_if_else_if.asp"] applied_in: [] github_commit: "" --- # [[PHP If Else If]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) PHP's time-of-day example uses `date("H")` returning a STRING that's then compared against string literals like `"20"` and `"10"` โ€” the comparisons `$t < "20"` still work correctly via PHP's loose typing (numeric string comparison), showing PHP doesn't require explicit numeric conversion for this common pattern. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`if...else`** โ€” two-branch conditional: true-block vs. false-block. [S1] - **`if...elseif...else`** โ€” multi-branch conditional: multiple sequential conditions plus a catch-all `else`. [S1] - **`elseif`** โ€” single keyword (not `else if`) in PHP syntax. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - if...else: `$t = date("H"); if ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; }`. [S1] - if...elseif...else: `if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; }`. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) ์†Œ์Šค์—์„œ ๋ชจ์ˆœ๋˜๋Š” ์ •๋ณด๋Š” ๋ฐœ๊ฒฌ๋˜์ง€ ์•Š์Œ. ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ํ˜„์žฌ ๋ฐœ๊ฒฌ๋œ ์‹ค์ œ ์ ์šฉ ์‚ฌ๋ก€๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค โ€” ์‹œ๊ฐ„๋Œ€๋ณ„ ์ธ์‚ฌ๋ง(์•„์นจ/๋‚ฎ/๋ฐค) ๋ถ„๊ธฐ๊ฐ€ elseif ์ฒด์ธ์˜ ๋Œ€ํ‘œ์  ์‹ค์ „ ์˜ˆ์‹œ๋‹ค. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) Three-way time-of-day branch with elseif (PHP): ```php $t = date("H"); if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.90 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[PHP Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[PHP If Operators]], [[PHP If Shorthand]], [[PHP Date]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** ๋‹ค์ค‘ ๋ถ„๊ธฐ ์กฐ๊ฑด๋ฌธ โ€” ์ถ•์•ฝํ˜•(Shorthand If) ์ฑ•ํ„ฐ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” PHP if...else Statements โ€” https://www.w3schools.com/php/php_if_else_if.asp ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP if...else Statements" page (Astra wiki-curation, P-Reinforce v3.1 format).