CKTIS / PHP
Bitwise AND with assignment (&=)
Keep in the variable only the flags allowed by the right mask.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
$value &= $operandKeep in the variable only the flags allowed by the right mask. A zero mask clears every flag.
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 both corresponding input bits are 1.
Evaluation
$value = 12; $value &= 10;→8$value = 12; $value &= 0;→0$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
8 0 7