--- id: php-arrays-remove title: "PHP Arrays Remove" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["unset", "array_splice", "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", "remove", "unset"] raw_sources: ["https://www.w3schools.com/php/php_arrays_remove.asp"] applied_in: [] github_commit: "" --- # [[PHP Arrays Remove]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `array_splice()` and `unset()` handle re-indexing completely differently β€” `array_splice()` automatically re-indexes the array from 0 after removal, while `unset()` leaves a GAP in the index sequence (removing index 1 leaves indices 0, 2, 3... with no 1), a distinction that matters if code later assumes contiguous indices. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`array_splice($arr, start, length)`** β€” removes a portion and auto-re-indexes from 0. [S1] - **`unset($arr[key])`** β€” removes one item by key/index; does NOT re-index, leaving gaps. [S1] - **`unset()` accepts multiple arguments** β€” can remove several items in one call. [S1] - **`array_diff($arr, [values])`** β€” returns a NEW array excluding specified VALUES (not keys). [S1] - **`array_pop($arr)`** β€” removes the last item. [S1] - **`array_shift($arr)`** β€” removes the first item. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - array_splice (re-indexes): `$cars = array("Volvo", "BMW", "Toyota"); array_splice($cars, 1, 1); // removes "BMW", re-indexed to [0=>"Volvo", 1=>"Toyota"]`. [S1] - unset (leaves a gap): `$cars = array("Volvo", "BMW", "Toyota"); unset($cars[1]); // [0=>"Volvo", 2=>"Toyota"] β€” no index 1`. [S1] - unset multiple: `unset($cars[0], $cars[1]);`. [S1] - unset by key (associative): `unset($cars["model"]);`. [S1] - array_diff (value-based removal): `$newarray = array_diff($cars, ["Mustang", 1964]); // note: values, not keys`. [S1] - array_pop / array_shift: `array_pop($cars); // removes last`; `array_shift($cars); // removes first`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **μž¬μΈλ±μ‹± μ—¬λΆ€μ˜ 차이**: array_splice()λŠ” μ‚­μ œ ν›„ 0λΆ€ν„° μžλ™ μž¬μΈλ±μ‹±ν•˜μ§€λ§Œ, unset()은 μž¬μΈλ±μ‹±ν•˜μ§€ μ•Šμ•„ μΈλ±μŠ€μ— 곡백이 μƒκΈ΄λ‹€λŠ” 점이 λͺ…ν™•νžˆ λŒ€λΉ„λ¨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” array_diff()둜 νŠΉμ • 값듀을 μ œμ™Έν•œ μƒˆ 배열을 λ§Œλ“œλŠ” νŒ¨ν„΄μ΄ μ—°κ΄€ λ°°μ—΄ ν•„ν„°λ§μ˜ λŒ€ν‘œ 사둀닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) unset() leaves an index gap, unlike array_splice() (PHP): ```php $cars = array("Volvo", "BMW", "Toyota"); unset($cars[1]); var_dump($cars); // [0]=>"Volvo", [2]=>"Toyota" β€” index 1 is missing, not re-indexed ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP Arrays Add]], [[PHP Arrays Sort]], [[PHP Arrays Functions]] - **μ°Έμ‘° λ§₯락:** λ°°μ—΄ ν•­λͺ© μ‚­μ œ β€” μ •λ ¬(Sort) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP Delete Array Items β€” https://www.w3schools.com/php/php_arrays_remove.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP Delete Array Items" page (Astra wiki-curation, P-Reinforce v3.1 format).