fork download
  1. <?php
  2.  
  3. for ($length=1; $length<=5;$length++) {
  4.  
  5. $half1=round(($length+1)/2); //ошибка тут!
  6. $half2=round($length/2); //верно
  7. $half3=round(($length+1)>>1); //верно
  8. $half4=$length+1>>1; //верно
  9.  
  10. echo "length:".$length." => ".$half1." ".$half2." ".$half3." ".$half4.PHP_EOL;
  11. }
Success #stdin #stdout 0.02s 24388KB
stdin
Standard input is empty
stdout
length:1 => 1 1 1 1
length:2 => 2 1 1 1
length:3 => 2 2 2 2
length:4 => 3 2 2 2
length:5 => 3 3 3 3