第一個範例以正數位移,結果為 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
?>