【问题标题】:php json_encode display with number not correct from array [duplicate]php json_encode显示数组中的数字不正确[重复]
【发布时间】:2019-06-01 11:03:23
【问题描述】:

这是我的数组

$data['myarray'] = ["1" => 1.2, "10" => 0.911, "50" => 0.811, "100" => 0.37];

如果使用 json_encode,它将显示为 json_encode($data['myarray']

{"1":{"1":1.2,"10":0.91100000000000003,"50":0.81100000000000005,"100":0.37}}

我不明白为什么我的 var 变成了其他数字

【问题讨论】:

  • 你的php版本是多少?
  • @Curious_Mind PHP 7.1.25
  • 这是 7.1.25 - 7.3.0 {"1":1.2,"10":0.911,"50":0.811,"100":0.37} 的输出,演示:3v4l.org/Es4IP#output
  • 是的,我已经在ideone.com/bIqFDR 测试过,工作正常。我已经升级到 7.26 但同样的问题。我不知道是什么错误

标签: php json


【解决方案1】:

添加此配置

ini_set('serialize_precision', 14); ini_set('precision', 14); 这是 php 7.1 的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-13
    • 2018-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-15
    相关资源
    最近更新 更多