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

The `xor` (exclusive OR) operator is a logical operator in PHP that evaluates to `true` if and only if exactly one of its operands evaluates to `true`. If both operands evaluate to `true`, or both evaluate to `false`, the expression returns `false`.

## Syntax

```php theme={"dark"}
$a xor $b
```

## Truth Table

The evaluation logic follows strict exclusive disjunction:

| `$a`    | `$b`    | `$a xor $b` |
| :------ | :------ | :---------- |
| `true`  | `true`  | `false`     |
| `true`  | `false` | `true`      |
| `false` | `true`  | `true`      |
| `false` | `false` | `false`     |

## Implicit Boolean Casting

Before evaluation, PHP implicitly casts non-boolean operands to boolean values according to standard PHP type-juggling rules.

```php theme={"dark"}
var_dump(1 xor 0);         // bool(true)  -> (true xor false)
var_dump("string" xor 1);  // bool(false) -> (true xor true)
var_dump("" xor null);     // bool(false) -> (false xor false)
```

## Operator Precedence

A critical mechanical detail of the `xor` operator is its position in the operator precedence table. `xor` has a lower precedence than the assignment operator (`=`). This requires explicit grouping via parentheses when assigning the result of an `xor` operation to a variable.

```php theme={"dark"}
// Without parentheses: Assignment takes precedence
$result = true xor false; 
// Evaluated as: ($result = true) xor false;
var_dump($result); // bool(true)

$result = true xor true;
// Evaluated as: ($result = true) xor true;
var_dump($result); // bool(true) - Incorrect logical result for the variable

// With parentheses: XOR takes precedence
$result = (true xor true);
var_dump($result); // bool(false) - Correct logical result
```

## Logical `xor` vs. Bitwise `^`

The `xor` operator is strictly a logical operator returning a boolean. It should not be confused with the caret symbol (`^`), which is the bitwise XOR operator. The bitwise operator evaluates the operands at the binary level and returns an integer or string, whereas the logical `xor` evaluates truthiness.

```php theme={"dark"}
// Logical XOR
var_dump(3 xor 6); 
// Evaluates as: (true xor true)
// Returns: bool(false)

// Bitwise XOR
var_dump(3 ^ 6);   
// Evaluates as: 011 ^ 110 (binary)
// Returns: int(5)
```

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