duanlan3598
2016-12-01 19:44
浏览 6
已采纳

我在php中得到了一些奇怪的答案。 有人可以解释原因吗?

Hi there i am learning php and i was just playing around with simple code but in my last code the computer is showing weird answer

And my browser shows result as "91919331.666666666667" I understand that 91 is result of the first echo and second 91 is result of 2nd echo and 93 is of 3rd and 31 is of 4th But after that why is the browser showing .666666666667

And also when i commented every echo but 2nd the result of that echo changed from 91 to 90

<?php
$number1 = 90;
$number2 = 3;
//echo ++$number1 ;
echo $number1++;
//echo $number1 + $number2 / $number2;
//echo ($number1 + $number2)/ $number2;
?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongsisui7562 2016-12-01 19:50
    已采纳
    <?php
    $number1 = 90;
    $number2 = 3;
    //increment number, display (91)
    echo ++$number1 ;
    
    //display number then increment (shows 91, number1 goes to 92)
    echo $number1++;
    
    //this will be 92 + (3 / 3) so 92+1 echos 93
    echo $number1 + $number2 / $number2;
    
    //this will be (92+3) / 3 so 31.6666666
    echo ($number1 + $number2)/ $number2;
    ?>
    
    点赞 打赏 评论

相关推荐 更多相似问题