In this paper, we describe the solution of the conversion of the digital object to scientific counting method after PHP using Json_decode. Share to everyone for your reference, as follows:
Problem:
Today in the Web game on Facebook points docking, Facebook passed a class JSON string, want to apply these parameters in the callball.php page, so a json_decode operation, found that the long numbers have become scientific counting method, This is not the result I want.
Workaround:
Do all aspects of the conversion process is not good to make:
$obj = ' {"order_id": 213477815351175, "buyer": 100001169269154} '; $obj = $this->json_decode ($obj, TRUE);p Rint_r ($obj );
Results:
Array ( [order_id] + 2.1347781535118E+14 [buyer] = 1.0000116926915E+14)
Finally, using PHP's own function Number_format (), the problem is resolved , the effect is as follows:
$obj = ' {"order_id": 213477815351175, "buyer": 100001169269154} '; $obj = $this->json_decode ($obj, TRUE); foreach ($obj As $key = $val) { $obj [$key]=number_format ($val, 0, ', ');} Print_r ($obj);
Results:
Array ( [order_id] = 213477815351175 [buyer] = 100001169269154)