json - INT more than 2147483647 always turn to 2147483647 in PHP -
my db id more 2147483647 (integer), if id turns 2147483647 when convert data json.
this json result
[ {"id":2147483647, "district_id":7171051, "name":"karame"}, {"id":2147483647, "district_id":7171051, "name":"ketang baru"}, {"id":2147483647, "district_id":7171051, "name":"wawonasa"}, {"id":2147483647, "district_id":7171051, "name":"ternate baru"}, {"id":2147483647, "district_id":7171051, "name":"ternate tanjung"}, {"id":2147483647, "district_id":7171051, "name":"kombos barat"}, {"id":2147483647, "district_id":7171051, "name":"kombos timur"}, {"id":2147483647, "district_id":7171051, "name":"singkil satu"}, {"id":2147483647, "district_id":7171051, "name":"singkil dua"} ]
my actual data
[ {"id":7171051001, "district_id":7171051, "name":"karame"}, {"id":7171051002, "district_id":7171051, "name":"ketang baru"}, {"id":7171051003, "district_id":7171051, "name":"wawonasa"}, {"id":7171051004, "district_id":7171051, "name":"ternate baru"}, {"id":7171051005, "district_id":7171051, "name":"ternate tanjung"}, {"id":7171051006, "district_id":7171051, "name":"kombos barat"}, {"id":7171051007, "district_id":7171051, "name":"kombos timur"}, {"id":7171051008, "district_id":7171051, "name":"singkil satu"}, {"id":7171051009, "district_id":7171051, "name":"singkil dua"} ]
i using laravel 5.4 how make actual id? thanks.
in php, can't have integer bigger php_int_max
, in 32-bit hardware (or 32-bit php) 2147483647 = 2^31-1
, number you're getting (for reference, in 64-bit it's 9223372036854775807 = 2^63-1
). and, original data, wherever you're getting from, has id string (notice quotes around them).
so, when cast integer, gets truncated 2147483647
. now, have 2 options:
- upgrade hardware/php version 64-bit. then, though, mentioned, still have
9223372036854775807
limit, higher. - if aren't doing arithmetics ids, could keep them string. there's nothing wrong alphanumeric id. in case, though, you'd have careful treat string along entire stack.
Comments
Post a Comment