第一个示例按正数进行移位,结果为 4,但第二个示例按负数进行移位,结果为 ArithmeticError(此示例对左移位相同)
<?php
$shif =1;
$number = 8;
$result = $number >> $shif;
echo $result; //// 1000 >> 01000 = 4
$shif =-1;
$number = 8;
$result = $number >> $shif;
////结果为 ArithmeticError
?>
(PHP 7, PHP 8)
第一个示例按正数进行移位,结果为 4,但第二个示例按负数进行移位,结果为 ArithmeticError(此示例对左移位相同)
<?php
$shif =1;
$number = 8;
$result = $number >> $shif;
echo $result; //// 1000 >> 01000 = 4
$shif =-1;
$number = 8;
$result = $number >> $shif;
////结果为 ArithmeticError
?>