Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Right shift with assignment (>>=)

Remove processed low bits from a stored bit field.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

$value >>= $operand

Remove processed low bits from a stored bit field. The next operation sees the next group of bits in the low positions.

Discard low bits by shifting an integer to the right. The sign bit fills high positions, so shifting −3 by one position gives −2. The right operand gives the number of bit positions. A negative shift count raises ArithmeticError. Shifting by zero positions preserves the number.

Evaluation

  • $value = 12; $value >>= 2; → 3
  • $value = 7; $value >>= 0; → 7
  • $value = (-3); $value >>= 1; → -2

Examples

<?php
$value = 12;
$value >>= 2;
echo json_encode($value), PHP_EOL;

$value = 7;
$value >>= 0;
echo json_encode($value), PHP_EOL;

$value = (-3);
$value >>= 1;
echo json_encode($value), PHP_EOL;

Result

3
7
-2

Sources