3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $arraydata = array('foo' => 3.0, 'bar' => 3.1); $jsondata = json_encode($arraydata); var_dump($arraydata); var_dump(json_encode($arraydata)); var_dump(json_encode($arraydata, JSON_PRESERVE_ZERO_FRACTION)); var_dump(json_decode($jsondata, true));
based on KYmuX
Output for 5.6.6 - 7.2.0
array(2) { ["foo"]=> float(3) ["bar"]=> float(3.1) } string(19) "{"foo":3,"bar":3.1}" string(21) "{"foo":3.0,"bar":3.1}" array(2) { ["foo"]=> int(3) ["bar"]=> float(3.1) }
Output for 5.5.0 - 5.6.5
array(2) { ["foo"]=> float(3) ["bar"]=> float(3.1) } string(19) "{"foo":3,"bar":3.1}" Notice: Use of undefined constant JSON_PRESERVE_ZERO_FRACTION - assumed 'JSON_PRESERVE_ZERO_FRACTION' in /in/IKLPU on line 7 Warning: json_encode() expects parameter 2 to be long, string given in /in/IKLPU on line 7 NULL array(2) { ["foo"]=> int(3) ["bar"]=> float(3.1) }