CKTIS / PHP
Bitwise OR with assignment (|=)
Enable the flags selected by the right mask in the variable.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
$value |= $operandEnable the flags selected by the right mask in the variable. Previously enabled flags remain set after repeated updates.
A mask works on individual bits of integers. When both operands are strings, PHP operates on their bytes and returns a string. A result bit is 1 when at least one corresponding input bit is 1.
Evaluation
$value = 12; $value |= 10;→14$value = 12; $value |= 0;→12$value = 7; $value |= 7;→7
Examples
<?php
$value = 12;
$value |= 10;
echo json_encode($value), PHP_EOL;
$value = 12;
$value |= 0;
echo json_encode($value), PHP_EOL;
$value = 7;
$value |= 7;
echo json_encode($value), PHP_EOL;
Result
14 12 7