Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Left shift (<<)

Move a bit field toward more significant positions.

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

Syntax

$value << $operand

Move a bit field toward more significant positions. Zeros fill the low positions and bits shifted beyond the integer width are lost.

The right operand gives the number of bit positions. A negative shift count raises ArithmeticError. Shifting by zero positions preserves the number.

Evaluation

  • 3 << 2 → 12
  • 7 << 0 → 7
  • (-3) << 1 → -6

Examples

<?php
echo json_encode(3 << 2), PHP_EOL;

echo json_encode(7 << 0), PHP_EOL;

echo json_encode((-3) << 1), PHP_EOL;

Result

12
7
-6

Sources