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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题