/ 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]
Expand |
Embed | Plain Text
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
Subscribe to comments
You need to login to post a comment.

asd
there is a native jsonencode() and jsondecode() in php since 5.2.1