--- id: php-arrays-add title: "PHP Arrays Add" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["array_push", "array_unshift", "array_merge", "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", "add"] raw_sources: ["https://www.w3schools.com/php/php_arrays_add.asp"] applied_in: [] github_commit: "" --- # [[PHP Arrays Add]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Adding multiple items to an associative array requires the `+=` operator instead of `array_push()` β€” `array_push()` only works with numeric-indexed arrays, so associative arrays need their own dedicated pattern (`$cars += ["color" => "red", "year" => 1964];`) to bulk-add named key-value pairs. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`[]` bracket append** β€” `$fruits[] = "Orange";` adds a single item to the end. [S1] - **`array_push($arr, ...)`** β€” adds one or more items to the end (indexed arrays). [S1] - **`+=` for associative bulk-add** β€” merges new key-value pairs into an associative array. [S1] - **`array_unshift($arr, ...)`** β€” adds one or more items to the BEGINNING. [S1] - **`array_splice($arr, offset, 0, item)`** β€” inserting with a length of 0 means nothing is removed, only inserted. [S1] - **`array_merge($arr1, $arr2, ...)`** β€” combines two or more arrays into one. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Single append: `$fruits = array("Apple", "Banana", "Cherry"); $fruits[] = "Orange";`. [S1] - Associative single-add: `$cars = array("brand" => "Ford", "model" => "Mustang"); $cars["color"] = "Red";`. [S1] - array_push (multiple, indexed): `array_push($fruits, "Orange", "Kiwi", "Lemon");`. [S1] - Associative bulk-add: `$cars += ["color" => "red", "year" => 1964];`. [S1] - array_unshift (prepend multiple): `array_unshift($fruits, "Orange", "Kiwi", "Lemon");`. [S1] - array_splice insert-only: `array_splice($fruits, 1, 0, "Orange"); // inserts at index 1, removes nothing`. [S1] - array_merge: `$result = array_merge($fruits1, $fruits2);`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **μ—°κ΄€ λ°°μ—΄ 닀쀑 μΆ”κ°€μ˜ νŠΉμˆ˜μ„±**: array_push()λŠ” 인덱슀 λ°°μ—΄μš©μ΄λ―€λ‘œ μ—°κ΄€ 배열에 μ—¬λŸ¬ ν‚€-κ°’ μŒμ„ ν•œ λ²ˆμ— μΆ”κ°€ν•˜λ €λ©΄ += μ—°μ‚°μžλ₯Ό 써야 ν•œλ‹€λŠ” 점이 ꡬ뢄됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” array_splice()둜 νŠΉμ • μœ„μΉ˜μ— ν•­λͺ©μ„ μ‚½μž…ν•˜λŠ” 것이 λ°°μ—΄ 쀑간 μ‚½μž…μ˜ ν‘œμ€€ νŒ¨ν„΄μ΄λ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Bulk-adding key-value pairs to an associative array (PHP): ```php $cars = array("brand" => "Ford", "model" => "Mustang"); $cars += ["color" => "red", "year" => 1964]; ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP Arrays Update]], [[PHP Arrays Remove]], [[PHP Arrays Functions]] - **μ°Έμ‘° λ§₯락:** λ°°μ—΄ ν•­λͺ© μΆ”κ°€ 방법 β€” ν•­λͺ© μ‚­μ œ(Remove) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP Add Array Items β€” https://www.w3schools.com/php/php_arrays_add.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP Add Array Items" page (Astra wiki-curation, P-Reinforce v3.1 format).