【问题标题】:Why does the gettype() say it's a double but var_dump() says float?为什么 gettype() 说它是 double 而 var_dump() 说 float?
【发布时间】:2011-12-22 03:38:38
【问题描述】:

为什么 gettype() 说它是 double 而 var_dump() 说是 float?

$number = 1234567890123456789;
echo "Number: {$number} is a ". gettype($number) . "\n";
var_dump($number);

回复:

编号:1.23456789012E+18 是双精度
浮动(1.23456789012E+18)

【问题讨论】:

    标签: php gettype var-dump


    【解决方案1】:

    【讨论】:

    • 这是我的问题
    【解决方案2】:

    直接来自 PHP.net (gettype()):

    返回字符串的可能值为:

    ... “double”(由于历史原因,在浮点数的情况下返回“double”,而不仅仅是“float”) ...

    【讨论】:

      【解决方案3】:
      <br>
      <?php 
              /*begins with a function that runs a Console msg for PHP */
      function console_sn($txt){
      $temp = "";
      $temp .= "<script>";
      $temp .= "console.info('frm_PHP: '+'";
      $temp .= $txt;
      $temp .= "');";
      $temp .= "</script>";
      echo $temp;
      }
      echo("<br><hr><br>");
      //end of PHP console function
      
      //Main primary code for this Example begins below
      
      //run these examples below in your test PHP file and see the results in your JS console window
      
      //e.g.#1
      $code1 = "1212";
      console_sn(gettype(floatval($code1)));
      
      //e.g.#2
      $code2 = "1212sn";
      console_sn(gettype(floatval($code2)));
      
      //e.g.#3
      $code3 = "1212";
      console_sn(gettype((trim($code3))*1));
      
      //e.g.#4
      $code4 = "1212sn";
      console_sn(gettype((trim($code4))*1));
      
      ?>
      

      【讨论】:

      • 将上面的代码块复制并粘贴到您的 PHP 测试文件中,然后查看结果出现在您的 Javascript 控制台 窗口中。
      猜你喜欢
      • 2014-01-28
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-24
      相关资源
      最近更新 更多