> ## 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 Bitwise OR

The `|` operator in PHP is the bitwise inclusive OR operator. It evaluates the binary representations of two operands and performs a logical OR operation on each corresponding pair of bits. If a bit is `1` in the left operand, the right operand, or both, the corresponding bit in the result is set to `1`. The result bit is `0` only if both corresponding operand bits are `0`.

```php theme={"dark"}
$result = $operand1 | $operand2;
```

## Truth Table

\| Bit A | Bit B | Result (`A | B`) |
\| :---: | :---: | :---: |
\|   0   |   0   |   0   |
\|   0   |   1   |   1   |
\|   1   |   0   |   1   |
\|   1   |   1   |   1   |

## Integer Evaluation

When operating on integers, the engine aligns the binary sequences of both numbers and evaluates them bit-by-bit.

```php theme={"dark"}
$a = 5;  // Binary representation: 0000 0101
$b = 3;  // Binary representation: 0000 0011

$result = $a | $b; 
// Evaluation: 0000 0111
// Decimal output: 7
```

## String Evaluation

If *both* operands are strings, PHP performs the bitwise OR operation byte-by-byte, evaluating the underlying ASCII/byte values of the characters.

```php theme={"dark"}
$str1 = "A"; // ASCII 65, Binary: 0100 0001
$str2 = " "; // ASCII 32, Binary: 0010 0000

$result = $str1 | $str2; 
// Evaluation: 0110 0001 
// ASCII output: 97 (String: "a")
```

**String Length Discrepancies:** If the two string operands are of unequal length, the bitwise operation is performed up to the length of the *longer* string. The shorter string is treated as if it were padded with null bytes (`\x00`) to match the length of the longer string. Because a bitwise OR operation between any byte and a null byte (`0000 0000`) results in the original byte, the remaining trailing bytes of the longer string are appended to the result unmodified.

## Type Coercion Rules

The `|` operator enforces specific type juggling behaviors depending on the operands provided:

* **Float to Integer:** If an operand is a floating-point number, PHP truncates the fractional part and casts it to an integer before performing the bitwise operation.
* **Mixed Types (String and Int):** The byte-by-byte string evaluation is strictly reserved for when *both* operands are strings. If one operand is a string and the other is an integer (or float), the string must be a well-formed numeric string, which PHP will cast to an integer prior to evaluation. As of PHP 8.0, if the string is non-numeric, applying the `|` operator throws a `TypeError` rather than silently casting the string to `0`.

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