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

The `**` operator is the arithmetic exponentiation operator in PHP, used to raise a base operand to the power of an exponent operand. Introduced in PHP 5.6, it serves as the native syntactic equivalent to the `pow()` function.

## Syntax

```php theme={"dark"}
$result = $base ** $exponent;
```

## Associativity

Unlike most mathematical operators in PHP which are left-associative, the `**` operator is **right-associative**. When multiple exponentiation operators are chained in a single expression, the evaluation engine processes them from right to left.

```php theme={"dark"}
$result = 2 ** 3 ** 2; 

// Evaluated as: 2 ** (3 ** 2) -> 2 ** 9 -> 512
// NOT evaluated as: (2 ** 3) ** 2 -> 8 ** 2 -> 64
```

## Precedence

The `**` operator has a higher operator precedence than standard multiplicative (`*`, `/`, `%`) and additive (`+`, `-`) operators.

Crucially, it also has a higher precedence than the unary negation operator (`-`). If you intend to raise a negative number to a power, the base must be explicitly wrapped in parentheses.

```php theme={"dark"}
$a = -2 ** 2;   // Evaluated as -(2 ** 2) -> -4
$b = (-2) ** 2; // Evaluated as (-2) ** 2 -> 4
```

## Type Resolution and Coercion

The return type of the `**` operator is dynamically resolved by the Zend Engine based on the operands and the mathematical result:

* **`int`**: Returned if both operands are integers, the exponent is greater than or equal to zero, and the resulting value does not exceed `PHP_INT_MAX` (integer overflow).
* **`float`**: Returned if either operand is a float, if the exponent is negative (which mathematically yields a fraction), or if the calculated result exceeds the maximum integer bounds.

```php theme={"dark"}
var_dump(2 ** 3);   // int(8)
var_dump(2 ** -1);  // float(0.5)
var_dump(2.0 ** 3); // float(8)
```

## Compound Assignment

PHP provides a corresponding compound assignment operator (`**=`) to mutate a variable in place by raising its current value to the power of the right-hand operand.

```php theme={"dark"}
$base = 4;
$base **= 2; // Equivalent to: $base = $base ** 2;
// $base is now int(16)
```

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