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); 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) } {"foo":3.0,"bar":3.1} Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in /in/rNUMJ:7 Stack trace: #0 {main} thrown in /in/rNUMJ on line 7
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
array(2) { ["foo"]=> float(3) ["bar"]=> float(3.1) } {"foo":3.0,"bar":3.1} Recoverable fatal error: Object of class stdClass could not be converted to string in /in/rNUMJ on line 7
Process exited with code 255.
Output for 5.6.6 - 5.6.40, 7.0.0 - 7.0.33
array(2) { ["foo"]=> float(3) ["bar"]=> float(3.1) } {"foo":3.0,"bar":3.1} Catchable fatal error: Object of class stdClass could not be converted to string in /in/rNUMJ on line 7
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) } Notice: Use of undefined constant JSON_PRESERVE_ZERO_FRACTION - assumed 'JSON_PRESERVE_ZERO_FRACTION' in /in/rNUMJ on line 6 Warning: json_encode() expects parameter 2 to be long, string given in /in/rNUMJ on line 6 Catchable fatal error: Object of class stdClass could not be converted to string in /in/rNUMJ on line 7
Process exited with code 255.

preferences:
253.31 ms | 402 KiB | 329 Q