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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)