> ## 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 Logical NOT

The `!` (Logical NOT) operator is a unary operator that negates the boolean value of a given expression. It evaluates the operand, implicitly casts it to a boolean if necessary, and returns the inverse boolean value: `true` becomes `false`, and `false` becomes `true`.

```php theme={"dark"}
!$expression
```

## Mechanics and Type Juggling

Because PHP is a dynamically typed language, the `!` operator relies on PHP's internal type juggling rules. Before negation occurs, the operand is evaluated for its boolean equivalent (truthiness).

If the operand evaluates to a *falsy* value, the `!` operator returns `true`. If the operand evaluates to a *truthy* value, it returns `false`.

The following values are strictly evaluated as falsy in PHP, meaning the `!` operator will return `true` when applied to them:

* The boolean `false`
* The integer `0`
* The float `0.0`
* The empty string `""` and the string `"0"`
* An empty array `[]`
* The special type `null`

```php theme={"dark"}
// Strict boolean negation
var_dump(!true);      // bool(false)
var_dump(!false);     // bool(true)

// Implicit boolean casting (Type Juggling)
var_dump(!0);         // bool(true)  - 0 is falsy
var_dump(!1);         // bool(false) - 1 is truthy
var_dump(!"");        // bool(true)  - empty string is falsy
var_dump(!"0");       // bool(true)  - string "0" is falsy
var_dump(!"PHP");     // bool(false) - non-empty string is truthy
var_dump(![]);        // bool(true)  - empty array is falsy
var_dump(![1, 2]);    // bool(false) - populated array is truthy
var_dump(!null);      // bool(true)  - null is falsy
```

## Operator Precedence and Associativity

The `!` operator is right-associative and possesses a high operator precedence. It binds tighter than comparison operators (e.g., `==`, `===`, `<`, `>`) and binary logical operators (e.g., `&&`, `||`, `and`, `or`).

Because of this high precedence, the `!` operator will evaluate its immediate right-hand operand before subsequent comparisons occur, which often necessitates the use of parentheses to achieve the desired evaluation order.

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

// Evaluates as (!true) == false -> false == false -> true
var_dump(!$a == $b); 

// Evaluates as !(true == false) -> !(false) -> true
var_dump(!($a == $b));
```

## Double Negation (`!!`)

Applying the Logical NOT operator twice sequentially (`!!`) acts as an implicit boolean cast. The first `!` coerces the operand to a boolean and inverts it; the second `!` inverts it back, effectively returning the strict boolean representation of the original value. This is functionally identical to using the `(bool)` cast.

```php theme={"dark"}
var_dump(!!"PHP"); // bool(true)
var_dump(!!0);     // bool(false)
```

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