3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $chars = explode(", ", "¦, '¨, '?, '´, '¸, 'À, 'Á, 'Â, 'Ã, 'Ä, 'Å"); $products = array(); for($i=0; $i < 10; $i++) { $product = array(); $product["pid"] = $chars[$i]; $products[] = array_map("utf8_encode", $product);; // insert product into array } $data = array( 'success' => 1, 'products' => $products ); $json = json_encode($data, JSON_PRETTY_PRINT); echo $json; var_dump(json_decode($json, true));
based on r6nNK
Output for 5.4.0 - 7.3.1
{ "success": 1, "products": [ { "pid": "\u00c3\u0082\u00c2\u00a6" }, { "pid": "'\u00c3\u0082\u00c2\u00a8" }, { "pid": "'?" }, { "pid": "'\u00c3\u0082\u00c2\u00b4" }, { "pid": "'\u00c3\u0082\u00c2\u00b8" }, { "pid": "'\u00c3\u0083\u00e2\u0082\u00ac" }, { "pid": "'\u00c3\u0083\u00c2\u0081" }, { "pid": "'\u00c3\u0083\u00e2\u0080\u009a" }, { "pid": "'\u00c3\u0083\u00c6\u0092" }, { "pid": "'\u00c3\u0083\u00e2\u0080\u009e" } ] }array(2) { ["success"]=> int(1) ["products"]=> array(10) { [0]=> array(1) { ["pid"]=> string(8) "¦" } [1]=> array(1) { ["pid"]=> string(9) "'¨" } [2]=> array(1) { ["pid"]=> string(2) "'?" } [3]=> array(1) { ["pid"]=> string(9) "'´" } [4]=> array(1) { ["pid"]=> string(9) "'¸" } [5]=> array(1) { ["pid"]=> string(11) "'À" } [6]=> array(1) { ["pid"]=> string(9) "'Á" } [7]=> array(1) { ["pid"]=> string(11) "'Â" } [8]=> array(1) { ["pid"]=> string(9) "'Ã" } [9]=> array(1) { ["pid"]=> string(11) "'Ä" } } }
Output for 5.3.0 - 5.3.29
Notice: Use of undefined constant JSON_PRETTY_PRINT - assumed 'JSON_PRETTY_PRINT' in /in/qnvpe on line 17 Warning: json_encode() expects parameter 2 to be long, string given in /in/qnvpe on line 17 NULL
Output for 5.2.0 - 5.2.17
Notice: Use of undefined constant JSON_PRETTY_PRINT - assumed 'JSON_PRETTY_PRINT' in /in/qnvpe on line 17 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/qnvpe on line 17 NULL
Output for 5.0.0 - 5.1.6
Fatal error: Call to undefined function json_encode() in /in/qnvpe on line 17
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_encode() in /in/qnvpe on line 17
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: json_encode() in /in/qnvpe on line 17
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_encode() in /in/qnvpe on line 17