> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP Addition Assignment

The `+=` operator is the addition assignment operator in PHP. It evaluates the expression on its right side, adds that value to the variable on its left side, and assigns the resulting value back to the left-side variable.

```php theme={"dark"}
$a += $b;
```

This operation is semantically equivalent to the standard assignment combined with the arithmetic addition operator:

```php theme={"dark"}
$a = $a + $b;
```

## Type-Specific Mechanics

The behavior of the `+=` operator depends strictly on the data types of the operands involved. PHP utilizes dynamic typing and type juggling, which affects how this operator resolves.

**1. Numeric Types (Integers and Floats)**
When both operands are numeric, standard arithmetic addition is performed. If the result of an integer addition exceeds the `PHP_INT_MAX` boundary, the resulting value is automatically promoted to a `float`.

```php theme={"dark"}
$val = 10;
$val += 5.5; // $val is implicitly cast to float(15.5)
```

**2. Arrays**
When applied to arrays, `+=` acts as the array union assignment operator. It appends elements from the right-hand array to the left-hand array. If a string or integer key exists in both arrays, the value from the left-hand array is preserved, and the right-hand value is discarded.

```php theme={"dark"}
$arr1 = ['a' => 1, 'b' => 2];
$arr2 = ['b' => 99, 'c' => 3];
$arr1 += $arr2; 
// $arr1 evaluates to: ['a' => 1, 'b' => 2, 'c' => 3]
```

**3. Strings and Type Coercion**
If the operands are strings, PHP attempts numeric type coercion prior to the addition.

* **Numeric Strings:** Strings containing valid numbers (e.g., `"10"`, `"3.14"`) are cast to `int` or `float` before the addition is executed.
* **Non-Numeric Strings:** In PHP 8.0 and later, attempting to use `+=` with a non-numeric string throws a `TypeError`.

```php theme={"dark"}
$num = 5;
$num += "20"; // "20" is coerced to int(20). $num becomes int(25).
```

## Return Value and Chaining

In PHP, assignment operations are expressions. The `+=` operator evaluates to the final assigned value of the left operand. Because it returns a value, the operator can be chained or embedded within larger expressions.

```php theme={"dark"}
$a = 5;
$b = 10;
$c = ($a += $b); 
// $a is assigned 15. 
// The expression ($a += $b) evaluates to 15.
// $c is assigned 15.
```

## Operator Precedence and Associativity

The `+=` operator shares the same precedence level as the standard assignment operator (`=`) and other compound assignment operators (such as `-=`, `*=`, `.=`). It is right-associative, meaning that if multiple assignment operators appear in a single statement, the expression is evaluated and grouped from right to left.

```php theme={"dark"}
$a = 5;
$b = 10;
$a += $b += 5;
// Evaluates as: $a += ($b += 5)
// $b becomes 15, then $a becomes 20.
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor PHP Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
