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;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀