/ Published in: JavaScript

SEE http://json.org/ for PHP JSON Libraries.
grunt knuckle drag brute force ugly escapes for quotes make a php array a json string
Produces trailing commas which some Javascript Librarys can't deal with.*
_*NOOB NOTE [a comma is added at the end of each array key/value set]_
grunt knuckle drag brute force ugly escapes for quotes make a php array a json string
Produces trailing commas which some Javascript Librarys can't deal with.*
_*NOOB NOTE [a comma is added at the end of each array key/value set]_
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function array_to_json_string($arraydata) { $output = ""; $output .= "{"; foreach($arraydata as $key=>$val){ if (is_array($val)) { $output .= "\"".$key."\" : [{"; foreach($val as $subkey=>$subval){ $output .= "\"".$subkey."\" : \"".$subval."\","; } $output .= "}],"; } else { $output .= "\"".$key."\" : \"".$val."\","; } } $output .= "}"; return $output; }
Comments
