> ## 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 Assignment

The `=` operator in PHP is the basic assignment operator. It evaluates the expression on its right-hand side (RHS) and writes the resulting value into the memory location referenced by the operand on its left-hand side (LHS).

```php theme={"dark"}
$lvalue = expression;
```

## Technical Characteristics

**L-values and R-values**
The LHS operand must be a valid l-value (a variable, array index, or object property). The RHS operand can be any valid r-value, which includes literals, variables, function return values, or complex expressions.

**Return Value**
In PHP, assignment is an expression, not just a statement. The `=` operator returns the value that was assigned to the LHS. This allows the assignment operation to be embedded within larger expressions.

```php theme={"dark"}
// The expression ($b = 5) assigns 5 to $b and evaluates to 5.
// $a is then assigned the result of 5 + 10.
$a = ($b = 5) + 10; 
```

**Associativity**
The `=` operator has right-to-left associativity. When multiple assignment operators are chained, the PHP engine evaluates the rightmost assignment first and propagates the return value to the left.

```php theme={"dark"}
// Evaluated as: $x = ($y = ($z = 0));
$x = $y = $z = 0; 
```

## Memory and Evaluation Behavior

The behavior of the `=` operator depends on the data type of the RHS expression:

**1. Assignment by Value (Scalars and Arrays)**
For scalar types (integers, floats, strings, booleans) and arrays, the `=` operator performs assignment *by value*. PHP creates a copy of the RHS value and assigns it to the LHS. Subsequent modifications to the LHS variable do not affect the RHS variable. *(Note: Internally, PHP optimizes array assignment using Copy-on-Write (CoW), deferring actual memory duplication until one of the variables is modified).*

```php theme={"dark"}
$a = [1, 2, 3];
$b = $a; // $b receives a copy of the array
```

**2. Object Identifier Assignment**
When the RHS is an object, the `=` operator does not copy the object itself. Instead, it copies the **object identifier**. Both the LHS and RHS variables will hold distinct copies of the identifier that point to the exact same object instance in memory.

```php theme={"dark"}
$objA = new stdClass();
$objB = $objA; // Both variables point to the same instance
```

**3. Reference Assignment (`=&`)**
To bypass standard assignment behavior and bind two variables to the exact same memory address (zval), the `=` operator must be combined with the reference operator (`&`). This creates an alias, meaning neither variable owns the value exclusively.

```php theme={"dark"}
$x = 100;
$y =& $x; // $y is now a reference to $x
```

<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>
