JavaScript PHP数组到JSON字符串
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript PHP数组到JSON字符串相关的知识,希望对你有一定的参考价值。
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;
}
以上是关于JavaScript PHP数组到JSON字符串的主要内容,如果未能解决你的问题,请参考以下文章