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($jsondata); echo json_encode($arraydata, JSON_PRESERVE_ZERO_FRACTION); echo json_decode($jsondata, true);
based on DCb3f
Output for 5.6.6 - 7.2.0
array(2) { ["foo"]=> float(3) ["bar"]=> float(3.1) } string(19) "{"foo":3,"bar":3.1}" {"foo":3.0,"bar":3.1} Notice: Array to string conversion in /in/NvCKU on line 8 Array
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/NvCKU on line 7 Warning: json_encode() expects parameter 2 to be long, string given in /in/NvCKU on line 7 Notice: Array to string conversion in /in/NvCKU on line 8 Array