-1

When using json_decode I am getting fields with unexpected strings. My json file is:

{
buyer_accepts_marketing: false,
cart_token: "eeafa272cebfd4b22385bc4b645e762c",
id: 327474488104976400,
}

and my relevant php code is

$info = json_decode($file,true);
print $info["id"];
echo "<br>";
print $info["cart_token"];

The Output I am getting is

3.2747448810498E+17

eeafa272cebfd4b22385bc4b645e762c

Why am I not getting the correct value of id?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Abey
  • 1,408
  • 11
  • 26

1 Answers1

0

It happening because the value of id is out of the range. Try to create it as string. if it is changed to string then it will work properly.

Integer overflow

If PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the integer type will return a float instead.
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87