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

An operator in PHP is a symbol or keyword that instructs the Zend Engine to perform a specific mathematical, relational, bitwise, logical, or type-checking operation on one or more operands (values, variables, or expressions) to evaluate and return a single resulting value.

Operators are classified by their **arity** (the number of operands they accept):

* **Unary:** Operates on a single operand (e.g., `!$a`, `++$a`).
* **Binary:** Operates on two operands (e.g., `$a + $b`).
* **Ternary:** Operates on three operands (e.g., `$a ? $b : $c`).

## Operator Categories and Syntax

### 1. Arithmetic Operators

Perform standard mathematical operations. The modulo operator (`%`) strips the fractional part of operands before processing. Crucially, the sign of the modulo result always matches the dividend (the left operand). For example, `-5 % 3` evaluates to `-2`. The exponentiation operator (`**`) is right-associative.

```php theme={"dark"}
+$a;      // Identity: Conversion to int or float
-$a;      // Negation: Opposite of $a
$a + $b;  // Addition
$a - $b;  // Subtraction
$a * $b;  // Multiplication
$a / $b;  // Division: Returns float unless both operands are integers (or integer-strings) and evenly divisible, which returns an integer.
$a % $b;  // Modulo (integer remainder). Sign matches $a.
$a ** $b; // Exponentiation
```

### 2. Incrementing/Decrementing Operators

Unary operators used to increment or decrement a variable's value by one. The position of the operator determines whether the operation occurs before or after the value is returned.

```php theme={"dark"}
++$a; // Pre-increment: Increments $a by one, then returns $a
$a++; // Post-increment: Returns $a, then increments $a by one
--$a; // Pre-decrement: Decrements $a by one, then returns $a
$a--; // Post-decrement: Returns $a, then decrements $a by one
```

### 3. Assignment Operators

Bind a value to a variable. The basic assignment operator (`=`) evaluates to the assigned value, allowing for chained assignments. Compound assignment operators perform an operation and assign the result in a single step.

```php theme={"dark"}
$a = $b;   // Basic assignment
$a += $b;  // Equivalent to: $a = $a + $b
$a .= $b;  // Equivalent to: $a = $a . $b (String concatenation)
$a ??= $b; // Null coalescing assignment: assigns $b to $a if $a is null
```

### 4. Comparison Operators

Evaluate the relationship between two operands, returning a boolean. PHP distinguishes between loose comparison (allows type coercion) and strict comparison (checks both value and type).

```php theme={"dark"}
$a == $b;   // Equal (loose: type coercion applied)
$a === $b;  // Identical (strict: same value and type)
$a != $b;   // Not equal (loose)
$a !== $b;  // Not identical (strict)
$a < $b;    // Less than
$a >= $b;   // Greater than or equal to
$a <=> $b;  // Spaceship: Returns -1, 0, or 1 (less than, equal, greater than)
```

### 5. Logical Operators

Evaluate boolean logic. PHP implements short-circuit evaluation for logical operators. PHP provides two sets of logical operators with different precedence levels (`&&`/`||` have higher precedence than `and`/`or`).

The `and` and `or` operators have lower precedence than the assignment operator (`=`). This means an expression like `$x = true and false;` evaluates as `($x = true) and false;`, leaving `$x` assigned to `true`.

```php theme={"dark"}
$a && $b;  // True if both are true (High precedence)
$a || $b;  // True if either is true (High precedence)
!$a;       // True if $a is not true
$a and $b; // True if both are true (Lower precedence than '=')
$a or $b;  // True if either is true (Lower precedence than '=')
$a xor $b; // True if either is true, but not both
```

### 6. Conditional (Ternary) Operators

Evaluate an expression for a boolean truth value and return one of two subsequent expressions based on that evaluation. PHP also supports a shorthand version known as the Elvis operator, which omits the middle expression.

```php theme={"dark"}
$a ? $b : $c; // Ternary: Evaluates to $b if $a is true, and $c if $a is false.
$a ?: $c;     // Elvis: Evaluates to $a if $a is true, and $c if $a is false.
```

### 7. Bitwise Operators

Evaluate and manipulate specific bits within an integer. If both operands are strings, the operation occurs on the ASCII values of the characters.

```php theme={"dark"}
$a & $b;  // And: Bits set in both $a and $b are set.
$a | $b;  // Or: Bits set in either $a or $b are set.
$a ^ $b;  // Xor: Bits set in $a or $b, but not both, are set.
~$a;      // Not (Unary): Flips all bits. For signed integers, this results in -$a - 1 due to two's complement.
$a << $b; // Shift left: Shift bits of $a left by $b steps.
$a >> $b; // Shift right: Shift bits of $a right by $b steps.
```

### 8. Type Operator

Determines if a PHP variable is an instantiated object of a specific class, a subclass, or implements a specific interface.

```php theme={"dark"}
$a instanceof ClassName; // True if $a is an object of ClassName or its descendants.
```

### 9. Null-Handling Operators

Provide concise syntax for evaluating `null` states without triggering undefined variable warnings or fatal errors.

```php theme={"dark"}
$a ?? $b;       // Null Coalescing: Returns $a if it exists and is not null; otherwise $b.
$a?->method();  // Nullsafe: Evaluates method() if $a is not null; otherwise returns null.
```

### 10. String and Array Operators

PHP uses specific operators for string concatenation and array union, distinct from arithmetic addition. Both the string concatenation and array union operators return a *new* value without modifying the original operands in-place.

```php theme={"dark"}
// String
$a . $b;   // Concatenation: Returns a new string combining $a and $b.

// Array
$a + $b;   // Union: Returns a new array merged by keys. Elements in $b whose keys already exist in $a are ignored.
$a == $b;  // Equality: True if $a and $b have the same key/value pairs.
$a === $b; // Identity: True if same key/value pairs in the same order and types.
```

### 11. Execution and Error Control

Specialized operators for system-level execution and error suppression.

```php theme={"dark"}
`command`; // Execution: Executes shell command and returns output (backticks).
@$a;       // Error Control: Suppresses diagnostic errors generated by expression $a.
```

## Precedence and Associativity

When multiple operators are present in an expression, **precedence** dictates the order of evaluation (e.g., `*` is evaluated before `+`). When operators have equal precedence, **associativity** dictates the evaluation direction:

* **Left-associative:** Evaluated from left to right (e.g., `-`, `.`).
* **Right-associative:** Evaluated from right to left (e.g., `=`, `**`).
* **Non-associative:** Cannot be chained together (e.g., `<=>`, `==`, and as of PHP 8.0, the ternary operator `? :`).

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