3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(2) { ["foo"]=> float(3) ["bar"]=> float(3.1) } string(19) "{"foo":3,"bar":3.1}" {"foo":3.0,"bar":3.1} Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in /in/DCb3f:8 Stack trace: #0 {main} thrown in /in/DCb3f on line 8
Process exited with code 255.
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33
array(2) { ["foo"]=> float(3) ["bar"]=> float(3.1) } string(19) "{"foo":3,"bar":3.1}" {"foo":3.0,"bar":3.1} Recoverable fatal error: Object of class stdClass could not be converted to string in /in/DCb3f on line 8
Process exited with code 255.
Output for 5.6.6 - 5.6.28, 7.0.0 - 7.0.20
array(2) { ["foo"]=> float(3) ["bar"]=> float(3.1) } string(19) "{"foo":3,"bar":3.1}" {"foo":3.0,"bar":3.1} Catchable fatal error: Object of class stdClass could not be converted to string in /in/DCb3f on line 8
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.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/DCb3f on line 7 Warning: json_encode() expects parameter 2 to be long, string given in /in/DCb3f on line 7 Catchable fatal error: Object of class stdClass could not be converted to string in /in/DCb3f on line 8
Process exited with code 255.

preferences:
200.46 ms | 402 KiB | 221 Q